hugetlbpage-book3e.c 2.7 KB

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