tlb.c 4.7 KB

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