Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
| 12 | #include <linux/config.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/smp.h> |
| 18 | #include <linux/mm.h> |
| 19 | |
| 20 | #include <asm/delay.h> |
| 21 | #include <asm/mmu_context.h> |
| 22 | #include <asm/pgalloc.h> |
| 23 | #include <asm/pal.h> |
| 24 | #include <asm/tlbflush.h> |
| 25 | |
| 26 | static struct { |
| 27 | unsigned long mask; /* mask of supported purge page-sizes */ |
| 28 | unsigned long max_bits; /* log2() of largest supported purge page-size */ |
| 29 | } purge; |
| 30 | |
| 31 | struct ia64_ctx ia64_ctx = { |
| 32 | .lock = SPIN_LOCK_UNLOCKED, |
| 33 | .next = 1, |
| 34 | .limit = (1 << 15) - 1, /* start out with the safe (architected) limit */ |
| 35 | .max_ctx = ~0U |
| 36 | }; |
| 37 | |
| 38 | DEFINE_PER_CPU(u8, ia64_need_tlb_flush); |
| 39 | |
| 40 | /* |
| 41 | * Acquire the ia64_ctx.lock before calling this function! |
| 42 | */ |
| 43 | void |
| 44 | wrap_mmu_context (struct mm_struct *mm) |
| 45 | { |
| 46 | unsigned long tsk_context, max_ctx = ia64_ctx.max_ctx; |
| 47 | struct task_struct *tsk; |
| 48 | int i; |
| 49 | |
| 50 | if (ia64_ctx.next > max_ctx) |
| 51 | ia64_ctx.next = 300; /* skip daemons */ |
| 52 | ia64_ctx.limit = max_ctx + 1; |
| 53 | |
| 54 | /* |
| 55 | * Scan all the task's mm->context and set proper safe range |
| 56 | */ |
| 57 | |
| 58 | read_lock(&tasklist_lock); |
| 59 | repeat: |
| 60 | for_each_process(tsk) { |
| 61 | if (!tsk->mm) |
| 62 | continue; |
| 63 | tsk_context = tsk->mm->context; |
| 64 | if (tsk_context == ia64_ctx.next) { |
| 65 | if (++ia64_ctx.next >= ia64_ctx.limit) { |
| 66 | /* empty range: reset the range limit and start over */ |
| 67 | if (ia64_ctx.next > max_ctx) |
| 68 | ia64_ctx.next = 300; |
| 69 | ia64_ctx.limit = max_ctx + 1; |
| 70 | goto repeat; |
| 71 | } |
| 72 | } |
| 73 | if ((tsk_context > ia64_ctx.next) && (tsk_context < ia64_ctx.limit)) |
| 74 | ia64_ctx.limit = tsk_context; |
| 75 | } |
| 76 | read_unlock(&tasklist_lock); |
| 77 | /* can't call flush_tlb_all() here because of race condition with O(1) scheduler [EF] */ |
| 78 | { |
| 79 | int cpu = get_cpu(); /* prevent preemption/migration */ |
| 80 | for (i = 0; i < NR_CPUS; ++i) |
| 81 | if (cpu_online(i) && (i != cpu)) |
| 82 | per_cpu(ia64_need_tlb_flush, i) = 1; |
| 83 | put_cpu(); |
| 84 | } |
| 85 | local_flush_tlb_all(); |
| 86 | } |
| 87 | |
| 88 | void |
Dean Roe | c1902aa | 2005-10-27 15:41:04 -0500 | [diff] [blame^] | 89 | ia64_global_tlb_purge (struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long nbits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
| 91 | static DEFINE_SPINLOCK(ptcg_lock); |
| 92 | |
Dean Roe | c1902aa | 2005-10-27 15:41:04 -0500 | [diff] [blame^] | 93 | if (mm != current->active_mm) { |
| 94 | flush_tlb_all(); |
| 95 | return; |
| 96 | } |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* HW requires global serialization of ptc.ga. */ |
| 99 | spin_lock(&ptcg_lock); |
| 100 | { |
| 101 | do { |
| 102 | /* |
| 103 | * Flush ALAT entries also. |
| 104 | */ |
| 105 | ia64_ptcga(start, (nbits<<2)); |
| 106 | ia64_srlz_i(); |
| 107 | start += (1UL << nbits); |
| 108 | } while (start < end); |
| 109 | } |
| 110 | spin_unlock(&ptcg_lock); |
| 111 | } |
| 112 | |
| 113 | void |
| 114 | local_flush_tlb_all (void) |
| 115 | { |
| 116 | unsigned long i, j, flags, count0, count1, stride0, stride1, addr; |
| 117 | |
| 118 | addr = local_cpu_data->ptce_base; |
| 119 | count0 = local_cpu_data->ptce_count[0]; |
| 120 | count1 = local_cpu_data->ptce_count[1]; |
| 121 | stride0 = local_cpu_data->ptce_stride[0]; |
| 122 | stride1 = local_cpu_data->ptce_stride[1]; |
| 123 | |
| 124 | local_irq_save(flags); |
| 125 | for (i = 0; i < count0; ++i) { |
| 126 | for (j = 0; j < count1; ++j) { |
| 127 | ia64_ptce(addr); |
| 128 | addr += stride1; |
| 129 | } |
| 130 | addr += stride0; |
| 131 | } |
| 132 | local_irq_restore(flags); |
| 133 | ia64_srlz_i(); /* srlz.i implies srlz.d */ |
| 134 | } |
| 135 | |
| 136 | void |
| 137 | flush_tlb_range (struct vm_area_struct *vma, unsigned long start, unsigned long end) |
| 138 | { |
| 139 | struct mm_struct *mm = vma->vm_mm; |
| 140 | unsigned long size = end - start; |
| 141 | unsigned long nbits; |
| 142 | |
Dean Roe | c1902aa | 2005-10-27 15:41:04 -0500 | [diff] [blame^] | 143 | #ifndef CONFIG_SMP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | if (mm != current->active_mm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | mm->context = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | return; |
| 147 | } |
Dean Roe | c1902aa | 2005-10-27 15:41:04 -0500 | [diff] [blame^] | 148 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | nbits = ia64_fls(size + 0xfff); |
| 151 | while (unlikely (((1UL << nbits) & purge.mask) == 0) && (nbits < purge.max_bits)) |
| 152 | ++nbits; |
| 153 | if (nbits > purge.max_bits) |
| 154 | nbits = purge.max_bits; |
| 155 | start &= ~((1UL << nbits) - 1); |
| 156 | |
| 157 | # ifdef CONFIG_SMP |
Dean Roe | c1902aa | 2005-10-27 15:41:04 -0500 | [diff] [blame^] | 158 | platform_global_tlb_purge(mm, start, end, nbits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | # else |
| 160 | do { |
| 161 | ia64_ptcl(start, (nbits<<2)); |
| 162 | start += (1UL << nbits); |
| 163 | } while (start < end); |
| 164 | # endif |
| 165 | |
| 166 | ia64_srlz_i(); /* srlz.i implies srlz.d */ |
| 167 | } |
| 168 | EXPORT_SYMBOL(flush_tlb_range); |
| 169 | |
| 170 | void __devinit |
| 171 | ia64_tlb_init (void) |
| 172 | { |
| 173 | ia64_ptce_info_t ptce_info; |
| 174 | unsigned long tr_pgbits; |
| 175 | long status; |
| 176 | |
| 177 | if ((status = ia64_pal_vm_page_size(&tr_pgbits, &purge.mask)) != 0) { |
| 178 | printk(KERN_ERR "PAL_VM_PAGE_SIZE failed with status=%ld;" |
| 179 | "defaulting to architected purge page-sizes.\n", status); |
| 180 | purge.mask = 0x115557000UL; |
| 181 | } |
| 182 | purge.max_bits = ia64_fls(purge.mask); |
| 183 | |
| 184 | ia64_get_ptce(&ptce_info); |
| 185 | local_cpu_data->ptce_base = ptce_info.base; |
| 186 | local_cpu_data->ptce_count[0] = ptce_info.count[0]; |
| 187 | local_cpu_data->ptce_count[1] = ptce_info.count[1]; |
| 188 | local_cpu_data->ptce_stride[0] = ptce_info.stride[0]; |
| 189 | local_cpu_data->ptce_stride[1] = ptce_info.stride[1]; |
| 190 | |
| 191 | local_flush_tlb_all(); /* nuke left overs from bootstrapping... */ |
| 192 | } |