tlb.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * TLB support routines.
  3. *
  4. * Copyright (C) 1998-2001, 2003 Hewlett-Packard Co
  5. * David Mosberger-Tang <davidm@hpl.hp.com>
  6. *
  7. * 08/02/00 A. Mallick <asit.k.mallick@intel.com>
  8. * Modified RID allocation for SMP
  9. * Goutham Rao <goutham.rao@intel.com>
  10. * IPI based ptc implementation and A-step IPI implementation.
  11. * Rohit Seth <rohit.seth@intel.com>
  12. * Ken Chen <kenneth.w.chen@intel.com>
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/sched.h>
  18. #include <linux/smp.h>
  19. #include <linux/mm.h>
  20. #include <linux/bootmem.h>
  21. #include <asm/delay.h>
  22. #include <asm/mmu_context.h>
  23. #include <asm/pgalloc.h>
  24. #include <asm/pal.h>
  25. #include <asm/tlbflush.h>
  26. #include <asm/dma.h>
  27. static struct {
  28. unsigned long mask; /* mask of supported purge page-sizes */
  29. unsigned long max_bits; /* log2 of largest supported purge page-size */
  30. } purge;
  31. struct ia64_ctx ia64_ctx = {
  32. .lock = SPIN_LOCK_UNLOCKED,
  33. .next = 1,
  34. .max_ctx = ~0U
  35. };
  36. DEFINE_PER_CPU(u8, ia64_need_tlb_flush);
  37. /*
  38. * Initializes the ia64_ctx.bitmap array based on max_ctx+1.
  39. * Called after cpu_init() has setup ia64_ctx.max_ctx based on
  40. * maximum RID that is supported by boot CPU.
  41. */
  42. void __init
  43. mmu_context_init (void)
  44. {
  45. ia64_ctx.bitmap = alloc_bootmem((ia64_ctx.max_ctx+1)>>3);
  46. ia64_ctx.flushmap = alloc_bootmem((ia64_ctx.max_ctx+1)>>3);
  47. }
  48. /*
  49. * Acquire the ia64_ctx.lock before calling this function!
  50. */
  51. void
  52. wrap_mmu_context (struct mm_struct *mm)
  53. {
  54. int i, cpu;
  55. unsigned long flush_bit;
  56. for (i=0; i <= ia64_ctx.max_ctx / BITS_PER_LONG; i++) {
  57. flush_bit = xchg(&ia64_ctx.flushmap[i], 0);
  58. ia64_ctx.bitmap[i] ^= flush_bit;
  59. }
  60. /* use offset at 300 to skip daemons */
  61. ia64_ctx.next = find_next_zero_bit(ia64_ctx.bitmap,
  62. ia64_ctx.max_ctx, 300);
  63. ia64_ctx.limit = find_next_bit(ia64_ctx.bitmap,
  64. ia64_ctx.max_ctx, ia64_ctx.next);
  65. /*
  66. * can't call flush_tlb_all() here because of race condition
  67. * with O(1) scheduler [EF]
  68. */
  69. cpu = get_cpu(); /* prevent preemption/migration */
  70. for_each_online_cpu(i)
  71. if (i != cpu)
  72. per_cpu(ia64_need_tlb_flush, i) = 1;
  73. put_cpu();
  74. local_flush_tlb_all();
  75. }
  76. void
  77. ia64_global_tlb_purge (struct mm_struct *mm, unsigned long start,
  78. unsigned long end, unsigned long nbits)
  79. {
  80. static DEFINE_SPINLOCK(ptcg_lock);
  81. if (mm != current->active_mm || !current->mm) {
  82. flush_tlb_all();
  83. return;
  84. }
  85. /* HW requires global serialization of ptc.ga. */
  86. spin_lock(&ptcg_lock);
  87. {
  88. do {
  89. /*
  90. * Flush ALAT entries also.
  91. */
  92. ia64_ptcga(start, (nbits<<2));
  93. ia64_srlz_i();
  94. start += (1UL << nbits);
  95. } while (start < end);
  96. }
  97. spin_unlock(&ptcg_lock);
  98. }
  99. void
  100. local_flush_tlb_all (void)
  101. {
  102. unsigned long i, j, flags, count0, count1, stride0, stride1, addr;
  103. addr = local_cpu_data->ptce_base;
  104. count0 = local_cpu_data->ptce_count[0];
  105. count1 = local_cpu_data->ptce_count[1];
  106. stride0 = local_cpu_data->ptce_stride[0];
  107. stride1 = local_cpu_data->ptce_stride[1];
  108. local_irq_save(flags);
  109. for (i = 0; i < count0; ++i) {
  110. for (j = 0; j < count1; ++j) {
  111. ia64_ptce(addr);
  112. addr += stride1;
  113. }
  114. addr += stride0;
  115. }
  116. local_irq_restore(flags);
  117. ia64_srlz_i(); /* srlz.i implies srlz.d */
  118. }
  119. void
  120. flush_tlb_range (struct vm_area_struct *vma, unsigned long start,
  121. unsigned long end)
  122. {
  123. struct mm_struct *mm = vma->vm_mm;
  124. unsigned long size = end - start;
  125. unsigned long nbits;
  126. #ifndef CONFIG_SMP
  127. if (mm != current->active_mm) {
  128. mm->context = 0;
  129. return;
  130. }
  131. #endif
  132. nbits = ia64_fls(size + 0xfff);
  133. while (unlikely (((1UL << nbits) & purge.mask) == 0) &&
  134. (nbits < purge.max_bits))
  135. ++nbits;
  136. if (nbits > purge.max_bits)
  137. nbits = purge.max_bits;
  138. start &= ~((1UL << nbits) - 1);
  139. preempt_disable();
  140. #ifdef CONFIG_SMP
  141. if (mm != current->active_mm || cpus_weight(mm->cpu_vm_mask) != 1) {
  142. platform_global_tlb_purge(mm, start, end, nbits);
  143. preempt_enable();
  144. return;
  145. }
  146. #endif
  147. do {
  148. ia64_ptcl(start, (nbits<<2));
  149. start += (1UL << nbits);
  150. } while (start < end);
  151. preempt_enable();
  152. ia64_srlz_i(); /* srlz.i implies srlz.d */
  153. }
  154. EXPORT_SYMBOL(flush_tlb_range);
  155. void __devinit
  156. ia64_tlb_init (void)
  157. {
  158. ia64_ptce_info_t ptce_info;
  159. unsigned long tr_pgbits;
  160. long status;
  161. if ((status = ia64_pal_vm_page_size(&tr_pgbits, &purge.mask)) != 0) {
  162. printk(KERN_ERR "PAL_VM_PAGE_SIZE failed with status=%ld;"
  163. "defaulting to architected purge page-sizes.\n", status);
  164. purge.mask = 0x115557000UL;
  165. }
  166. purge.max_bits = ia64_fls(purge.mask);
  167. ia64_get_ptce(&ptce_info);
  168. local_cpu_data->ptce_base = ptce_info.base;
  169. local_cpu_data->ptce_count[0] = ptce_info.count[0];
  170. local_cpu_data->ptce_count[1] = ptce_info.count[1];
  171. local_cpu_data->ptce_stride[0] = ptce_info.stride[0];
  172. local_cpu_data->ptce_stride[1] = ptce_info.stride[1];
  173. local_flush_tlb_all(); /* nuke left overs from bootstrapping... */
  174. }