hugetlbpage-book3e.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. static inline int mmu_get_tsize(int psize)
  11. {
  12. return mmu_psize_defs[psize].enc;
  13. }
  14. static inline int book3e_tlb_exists(unsigned long ea, unsigned long pid)
  15. {
  16. int found = 0;
  17. mtspr(SPRN_MAS6, pid << 16);
  18. if (mmu_has_feature(MMU_FTR_USE_TLBRSRV)) {
  19. asm volatile(
  20. "li %0,0\n"
  21. "tlbsx. 0,%1\n"
  22. "bne 1f\n"
  23. "li %0,1\n"
  24. "1:\n"
  25. : "=&r"(found) : "r"(ea));
  26. } else {
  27. asm volatile(
  28. "tlbsx 0,%1\n"
  29. "mfspr %0,0x271\n"
  30. "srwi %0,%0,31\n"
  31. : "=&r"(found) : "r"(ea));
  32. }
  33. return found;
  34. }
  35. void book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea,
  36. pte_t pte)
  37. {
  38. unsigned long mas1, mas2;
  39. u64 mas7_3;
  40. unsigned long psize, tsize, shift;
  41. unsigned long flags;
  42. struct mm_struct *mm;
  43. #ifdef CONFIG_PPC_FSL_BOOK3E
  44. int index, ncams;
  45. #endif
  46. if (unlikely(is_kernel_addr(ea)))
  47. return;
  48. mm = vma->vm_mm;
  49. #ifdef CONFIG_PPC_MM_SLICES
  50. psize = get_slice_psize(mm, ea);
  51. tsize = mmu_get_tsize(psize);
  52. shift = mmu_psize_defs[psize].shift;
  53. #else
  54. psize = vma_mmu_pagesize(vma);
  55. shift = __ilog2(psize);
  56. tsize = shift - 10;
  57. #endif
  58. /*
  59. * We can't be interrupted while we're setting up the MAS
  60. * regusters or after we've confirmed that no tlb exists.
  61. */
  62. local_irq_save(flags);
  63. if (unlikely(book3e_tlb_exists(ea, mm->context.id))) {
  64. local_irq_restore(flags);
  65. return;
  66. }
  67. #ifdef CONFIG_PPC_FSL_BOOK3E
  68. ncams = mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY;
  69. /* We have to use the CAM(TLB1) on FSL parts for hugepages */
  70. index = __get_cpu_var(next_tlbcam_idx);
  71. mtspr(SPRN_MAS0, MAS0_ESEL(index) | MAS0_TLBSEL(1));
  72. /* Just round-robin the entries and wrap when we hit the end */
  73. if (unlikely(index == ncams - 1))
  74. __get_cpu_var(next_tlbcam_idx) = tlbcam_index;
  75. else
  76. __get_cpu_var(next_tlbcam_idx)++;
  77. #endif
  78. mas1 = MAS1_VALID | MAS1_TID(mm->context.id) | MAS1_TSIZE(tsize);
  79. mas2 = ea & ~((1UL << shift) - 1);
  80. mas2 |= (pte_val(pte) >> PTE_WIMGE_SHIFT) & MAS2_WIMGE_MASK;
  81. mas7_3 = (u64)pte_pfn(pte) << PAGE_SHIFT;
  82. mas7_3 |= (pte_val(pte) >> PTE_BAP_SHIFT) & MAS3_BAP_MASK;
  83. if (!pte_dirty(pte))
  84. mas7_3 &= ~(MAS3_SW|MAS3_UW);
  85. mtspr(SPRN_MAS1, mas1);
  86. mtspr(SPRN_MAS2, mas2);
  87. if (mmu_has_feature(MMU_FTR_USE_PAIRED_MAS)) {
  88. mtspr(SPRN_MAS7_MAS3, mas7_3);
  89. } else {
  90. mtspr(SPRN_MAS7, upper_32_bits(mas7_3));
  91. mtspr(SPRN_MAS3, lower_32_bits(mas7_3));
  92. }
  93. asm volatile ("tlbwe");
  94. local_irq_restore(flags);
  95. }
  96. void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  97. {
  98. struct hstate *hstate = hstate_file(vma->vm_file);
  99. unsigned long tsize = huge_page_shift(hstate) - 10;
  100. __flush_tlb_page(vma ? vma->vm_mm : NULL, vmaddr, tsize, 0);
  101. }