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. |
Peter Keilty | dcc17d1 | 2005-10-31 16:44:47 -0500 | [diff] [blame] | 11 | * Rohit Seth <rohit.seth@intel.com> |
| 12 | * Ken Chen <kenneth.w.chen@intel.com> |
de Dinechin, Christophe (Integrity VM) | aec103b | 2007-12-13 15:03:07 +0000 | [diff] [blame] | 13 | * Christophe de Dinechin <ddd@hp.com>: Avoid ptc.e on memory allocation |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 14 | * Copyright (C) 2007 Intel Corp |
| 15 | * Fenghua Yu <fenghua.yu@intel.com> |
| 16 | * Add multiple ptc.g/ptc.ga instruction support in global tlb purge. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/smp.h> |
| 23 | #include <linux/mm.h> |
Peter Keilty | dcc17d1 | 2005-10-31 16:44:47 -0500 | [diff] [blame] | 24 | #include <linux/bootmem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include <asm/delay.h> |
| 28 | #include <asm/mmu_context.h> |
| 29 | #include <asm/pgalloc.h> |
| 30 | #include <asm/pal.h> |
| 31 | #include <asm/tlbflush.h> |
Peter Keilty | dcc17d1 | 2005-10-31 16:44:47 -0500 | [diff] [blame] | 32 | #include <asm/dma.h> |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 33 | #include <asm/processor.h> |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 34 | #include <asm/sal.h> |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 35 | #include <asm/tlb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | static struct { |
Matthew Wilcox | e088a4a | 2009-05-22 13:49:49 -0700 | [diff] [blame] | 38 | u64 mask; /* mask of supported purge page-sizes */ |
Chen, Kenneth W | 58cd908 | 2005-10-29 18:47:04 -0700 | [diff] [blame] | 39 | unsigned long max_bits; /* log2 of largest supported purge page-size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } purge; |
| 41 | |
| 42 | struct ia64_ctx ia64_ctx = { |
Milind Arun Choudhary | 8737d59 | 2007-04-15 22:51:23 +0530 | [diff] [blame] | 43 | .lock = __SPIN_LOCK_UNLOCKED(ia64_ctx.lock), |
| 44 | .next = 1, |
| 45 | .max_ctx = ~0U |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | DEFINE_PER_CPU(u8, ia64_need_tlb_flush); |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 49 | DEFINE_PER_CPU(u8, ia64_tr_num); /*Number of TR slots in current processor*/ |
| 50 | DEFINE_PER_CPU(u8, ia64_tr_used); /*Max Slot number used by kernel*/ |
| 51 | |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 52 | struct ia64_tr_entry *ia64_idtrs[NR_CPUS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
Peter Keilty | dcc17d1 | 2005-10-31 16:44:47 -0500 | [diff] [blame] | 55 | * Initializes the ia64_ctx.bitmap array based on max_ctx+1. |
| 56 | * Called after cpu_init() has setup ia64_ctx.max_ctx based on |
| 57 | * maximum RID that is supported by boot CPU. |
| 58 | */ |
| 59 | void __init |
| 60 | mmu_context_init (void) |
| 61 | { |
| 62 | ia64_ctx.bitmap = alloc_bootmem((ia64_ctx.max_ctx+1)>>3); |
| 63 | ia64_ctx.flushmap = alloc_bootmem((ia64_ctx.max_ctx+1)>>3); |
| 64 | } |
| 65 | |
| 66 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | * Acquire the ia64_ctx.lock before calling this function! |
| 68 | */ |
| 69 | void |
| 70 | wrap_mmu_context (struct mm_struct *mm) |
| 71 | { |
Chen, Kenneth W | 58cd908 | 2005-10-29 18:47:04 -0700 | [diff] [blame] | 72 | int i, cpu; |
Peter Keilty | dcc17d1 | 2005-10-31 16:44:47 -0500 | [diff] [blame] | 73 | unsigned long flush_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Peter Keilty | dcc17d1 | 2005-10-31 16:44:47 -0500 | [diff] [blame] | 75 | for (i=0; i <= ia64_ctx.max_ctx / BITS_PER_LONG; i++) { |
| 76 | flush_bit = xchg(&ia64_ctx.flushmap[i], 0); |
| 77 | ia64_ctx.bitmap[i] ^= flush_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
Peter Keilty | dcc17d1 | 2005-10-31 16:44:47 -0500 | [diff] [blame] | 79 | |
| 80 | /* use offset at 300 to skip daemons */ |
| 81 | ia64_ctx.next = find_next_zero_bit(ia64_ctx.bitmap, |
| 82 | ia64_ctx.max_ctx, 300); |
| 83 | ia64_ctx.limit = find_next_bit(ia64_ctx.bitmap, |
| 84 | ia64_ctx.max_ctx, ia64_ctx.next); |
| 85 | |
Chen, Kenneth W | 58cd908 | 2005-10-29 18:47:04 -0700 | [diff] [blame] | 86 | /* |
| 87 | * can't call flush_tlb_all() here because of race condition |
| 88 | * with O(1) scheduler [EF] |
| 89 | */ |
| 90 | cpu = get_cpu(); /* prevent preemption/migration */ |
| 91 | for_each_online_cpu(i) |
| 92 | if (i != cpu) |
| 93 | per_cpu(ia64_need_tlb_flush, i) = 1; |
| 94 | put_cpu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | local_flush_tlb_all(); |
| 96 | } |
| 97 | |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 98 | /* |
| 99 | * Implement "spinaphores" ... like counting semaphores, but they |
| 100 | * spin instead of sleeping. If there are ever any other users for |
| 101 | * this primitive it can be moved up to a spinaphore.h header. |
| 102 | */ |
| 103 | struct spinaphore { |
Tony Luck | 883a3ac | 2009-10-09 10:52:39 -0700 | [diff] [blame] | 104 | unsigned long ticket; |
| 105 | unsigned long serve; |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | static inline void spinaphore_init(struct spinaphore *ss, int val) |
| 109 | { |
Tony Luck | 883a3ac | 2009-10-09 10:52:39 -0700 | [diff] [blame] | 110 | ss->ticket = 0; |
| 111 | ss->serve = val; |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static inline void down_spin(struct spinaphore *ss) |
| 115 | { |
Tony Luck | 883a3ac | 2009-10-09 10:52:39 -0700 | [diff] [blame] | 116 | unsigned long t = ia64_fetchadd(1, &ss->ticket, acq), serve; |
| 117 | |
| 118 | if (time_before(t, ss->serve)) |
| 119 | return; |
| 120 | |
| 121 | ia64_invala(); |
| 122 | |
| 123 | for (;;) { |
Tony Luck | b70f4e8 | 2010-06-30 10:46:16 -0700 | [diff] [blame] | 124 | asm volatile ("ld8.c.nc %0=[%1]" : "=r"(serve) : "r"(&ss->serve) : "memory"); |
Tony Luck | 883a3ac | 2009-10-09 10:52:39 -0700 | [diff] [blame] | 125 | if (time_before(t, serve)) |
| 126 | return; |
| 127 | cpu_relax(); |
| 128 | } |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static inline void up_spin(struct spinaphore *ss) |
| 132 | { |
Tony Luck | 883a3ac | 2009-10-09 10:52:39 -0700 | [diff] [blame] | 133 | ia64_fetchadd(1, &ss->serve, rel); |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static struct spinaphore ptcg_sem; |
| 137 | static u16 nptcg = 1; |
| 138 | static int need_ptcg_sem = 1; |
| 139 | static int toolatetochangeptcgsem = 0; |
| 140 | |
| 141 | /* |
Fenghua Yu | a6c75b86 | 2008-03-14 13:57:08 -0700 | [diff] [blame] | 142 | * Kernel parameter "nptcg=" overrides max number of concurrent global TLB |
| 143 | * purges which is reported from either PAL or SAL PALO. |
| 144 | * |
| 145 | * We don't have sanity checking for nptcg value. It's the user's responsibility |
| 146 | * for valid nptcg value on the platform. Otherwise, kernel may hang in some |
| 147 | * cases. |
| 148 | */ |
| 149 | static int __init |
| 150 | set_nptcg(char *str) |
| 151 | { |
| 152 | int value = 0; |
| 153 | |
| 154 | get_option(&str, &value); |
| 155 | setup_ptcg_sem(value, NPTCG_FROM_KERNEL_PARAMETER); |
| 156 | |
| 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | __setup("nptcg=", set_nptcg); |
| 161 | |
| 162 | /* |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 163 | * Maximum number of simultaneous ptc.g purges in the system can |
| 164 | * be defined by PAL_VM_SUMMARY (in which case we should take |
| 165 | * the smallest value for any cpu in the system) or by the PAL |
| 166 | * override table (in which case we should ignore the value from |
| 167 | * PAL_VM_SUMMARY). |
| 168 | * |
Fenghua Yu | a6c75b86 | 2008-03-14 13:57:08 -0700 | [diff] [blame] | 169 | * Kernel parameter "nptcg=" overrides maximum number of simultanesous ptc.g |
| 170 | * purges defined in either PAL_VM_SUMMARY or PAL override table. In this case, |
| 171 | * we should ignore the value from either PAL_VM_SUMMARY or PAL override table. |
| 172 | * |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 173 | * Complicating the logic here is the fact that num_possible_cpus() |
| 174 | * isn't fully setup until we start bringing cpus online. |
| 175 | */ |
| 176 | void |
Fenghua Yu | a6c75b86 | 2008-03-14 13:57:08 -0700 | [diff] [blame] | 177 | setup_ptcg_sem(int max_purges, int nptcg_from) |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 178 | { |
Fenghua Yu | a6c75b86 | 2008-03-14 13:57:08 -0700 | [diff] [blame] | 179 | static int kp_override; |
| 180 | static int palo_override; |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 181 | static int firstcpu = 1; |
| 182 | |
| 183 | if (toolatetochangeptcgsem) { |
Hidetoshi Seto | e617fce | 2008-04-25 23:13:09 +0900 | [diff] [blame] | 184 | if (nptcg_from == NPTCG_FROM_PAL && max_purges == 0) |
| 185 | BUG_ON(1 < nptcg); |
| 186 | else |
| 187 | BUG_ON(max_purges < nptcg); |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 188 | return; |
| 189 | } |
| 190 | |
Fenghua Yu | a6c75b86 | 2008-03-14 13:57:08 -0700 | [diff] [blame] | 191 | if (nptcg_from == NPTCG_FROM_KERNEL_PARAMETER) { |
| 192 | kp_override = 1; |
| 193 | nptcg = max_purges; |
| 194 | goto resetsema; |
| 195 | } |
| 196 | if (kp_override) { |
| 197 | need_ptcg_sem = num_possible_cpus() > nptcg; |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | if (nptcg_from == NPTCG_FROM_PALO) { |
| 202 | palo_override = 1; |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 203 | |
| 204 | /* In PALO max_purges == 0 really means it! */ |
| 205 | if (max_purges == 0) |
| 206 | panic("Whoa! Platform does not support global TLB purges.\n"); |
| 207 | nptcg = max_purges; |
| 208 | if (nptcg == PALO_MAX_TLB_PURGES) { |
| 209 | need_ptcg_sem = 0; |
| 210 | return; |
| 211 | } |
| 212 | goto resetsema; |
| 213 | } |
Fenghua Yu | a6c75b86 | 2008-03-14 13:57:08 -0700 | [diff] [blame] | 214 | if (palo_override) { |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 215 | if (nptcg != PALO_MAX_TLB_PURGES) |
| 216 | need_ptcg_sem = (num_possible_cpus() > nptcg); |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | /* In PAL_VM_SUMMARY max_purges == 0 actually means 1 */ |
| 221 | if (max_purges == 0) max_purges = 1; |
| 222 | |
| 223 | if (firstcpu) { |
| 224 | nptcg = max_purges; |
| 225 | firstcpu = 0; |
| 226 | } |
| 227 | if (max_purges < nptcg) |
| 228 | nptcg = max_purges; |
| 229 | if (nptcg == PAL_MAX_PURGES) { |
| 230 | need_ptcg_sem = 0; |
| 231 | return; |
| 232 | } else |
| 233 | need_ptcg_sem = (num_possible_cpus() > nptcg); |
| 234 | |
| 235 | resetsema: |
| 236 | spinaphore_init(&ptcg_sem, max_purges); |
| 237 | } |
| 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | void |
Chen, Kenneth W | 58cd908 | 2005-10-29 18:47:04 -0700 | [diff] [blame] | 240 | ia64_global_tlb_purge (struct mm_struct *mm, unsigned long start, |
| 241 | unsigned long end, unsigned long nbits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
de Dinechin, Christophe (Integrity VM) | aec103b | 2007-12-13 15:03:07 +0000 | [diff] [blame] | 243 | struct mm_struct *active_mm = current->active_mm; |
| 244 | |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 245 | toolatetochangeptcgsem = 1; |
| 246 | |
de Dinechin, Christophe (Integrity VM) | aec103b | 2007-12-13 15:03:07 +0000 | [diff] [blame] | 247 | if (mm != active_mm) { |
| 248 | /* Restore region IDs for mm */ |
| 249 | if (mm && active_mm) { |
| 250 | activate_context(mm); |
| 251 | } else { |
| 252 | flush_tlb_all(); |
| 253 | return; |
| 254 | } |
Dean Roe | c1902aa | 2005-10-27 15:41:04 -0500 | [diff] [blame] | 255 | } |
| 256 | |
Fenghua Yu | 2046b94 | 2008-04-04 11:05:59 -0700 | [diff] [blame] | 257 | if (need_ptcg_sem) |
| 258 | down_spin(&ptcg_sem); |
| 259 | |
| 260 | do { |
| 261 | /* |
| 262 | * Flush ALAT entries also. |
| 263 | */ |
| 264 | ia64_ptcga(start, (nbits << 2)); |
| 265 | ia64_srlz_i(); |
| 266 | start += (1UL << nbits); |
| 267 | } while (start < end); |
| 268 | |
| 269 | if (need_ptcg_sem) |
| 270 | up_spin(&ptcg_sem); |
de Dinechin, Christophe (Integrity VM) | aec103b | 2007-12-13 15:03:07 +0000 | [diff] [blame] | 271 | |
| 272 | if (mm != active_mm) { |
| 273 | activate_context(active_mm); |
| 274 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | void |
| 278 | local_flush_tlb_all (void) |
| 279 | { |
| 280 | unsigned long i, j, flags, count0, count1, stride0, stride1, addr; |
| 281 | |
| 282 | addr = local_cpu_data->ptce_base; |
| 283 | count0 = local_cpu_data->ptce_count[0]; |
| 284 | count1 = local_cpu_data->ptce_count[1]; |
| 285 | stride0 = local_cpu_data->ptce_stride[0]; |
| 286 | stride1 = local_cpu_data->ptce_stride[1]; |
| 287 | |
| 288 | local_irq_save(flags); |
| 289 | for (i = 0; i < count0; ++i) { |
| 290 | for (j = 0; j < count1; ++j) { |
| 291 | ia64_ptce(addr); |
| 292 | addr += stride1; |
| 293 | } |
| 294 | addr += stride0; |
| 295 | } |
| 296 | local_irq_restore(flags); |
| 297 | ia64_srlz_i(); /* srlz.i implies srlz.d */ |
| 298 | } |
| 299 | |
| 300 | void |
Chen, Kenneth W | 58cd908 | 2005-10-29 18:47:04 -0700 | [diff] [blame] | 301 | flush_tlb_range (struct vm_area_struct *vma, unsigned long start, |
| 302 | unsigned long end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
| 304 | struct mm_struct *mm = vma->vm_mm; |
| 305 | unsigned long size = end - start; |
| 306 | unsigned long nbits; |
| 307 | |
Dean Roe | c1902aa | 2005-10-27 15:41:04 -0500 | [diff] [blame] | 308 | #ifndef CONFIG_SMP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | if (mm != current->active_mm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | mm->context = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | return; |
| 312 | } |
Dean Roe | c1902aa | 2005-10-27 15:41:04 -0500 | [diff] [blame] | 313 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | nbits = ia64_fls(size + 0xfff); |
Chen, Kenneth W | 58cd908 | 2005-10-29 18:47:04 -0700 | [diff] [blame] | 316 | while (unlikely (((1UL << nbits) & purge.mask) == 0) && |
| 317 | (nbits < purge.max_bits)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | ++nbits; |
| 319 | if (nbits > purge.max_bits) |
| 320 | nbits = purge.max_bits; |
| 321 | start &= ~((1UL << nbits) - 1); |
| 322 | |
Hugh Dickins | 663b97f | 2005-10-29 18:16:28 -0700 | [diff] [blame] | 323 | preempt_disable(); |
Chen, Kenneth W | ce9eed5 | 2006-03-06 14:12:54 -0800 | [diff] [blame] | 324 | #ifdef CONFIG_SMP |
Rusty Russell | 5d8c39f | 2009-03-16 14:12:48 +1030 | [diff] [blame] | 325 | if (mm != current->active_mm || cpumask_weight(mm_cpumask(mm)) != 1) { |
Chen, Kenneth W | ce9eed5 | 2006-03-06 14:12:54 -0800 | [diff] [blame] | 326 | platform_global_tlb_purge(mm, start, end, nbits); |
| 327 | preempt_enable(); |
| 328 | return; |
| 329 | } |
| 330 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | do { |
| 332 | ia64_ptcl(start, (nbits<<2)); |
| 333 | start += (1UL << nbits); |
| 334 | } while (start < end); |
Hugh Dickins | 663b97f | 2005-10-29 18:16:28 -0700 | [diff] [blame] | 335 | preempt_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | ia64_srlz_i(); /* srlz.i implies srlz.d */ |
| 337 | } |
| 338 | EXPORT_SYMBOL(flush_tlb_range); |
| 339 | |
Greg Kroah-Hartman | 5b5e76e | 2012-12-21 14:05:13 -0800 | [diff] [blame] | 340 | void ia64_tlb_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | { |
Jes Sorensen | 256a7e0 | 2007-07-11 17:26:30 +0200 | [diff] [blame] | 342 | ia64_ptce_info_t uninitialized_var(ptce_info); /* GCC be quiet */ |
Matthew Wilcox | e088a4a | 2009-05-22 13:49:49 -0700 | [diff] [blame] | 343 | u64 tr_pgbits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | long status; |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 345 | pal_vm_info_1_u_t vm_info_1; |
| 346 | pal_vm_info_2_u_t vm_info_2; |
| 347 | int cpu = smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
| 349 | if ((status = ia64_pal_vm_page_size(&tr_pgbits, &purge.mask)) != 0) { |
Joe Perches | c2eeb32 | 2007-11-19 17:47:53 -0800 | [diff] [blame] | 350 | printk(KERN_ERR "PAL_VM_PAGE_SIZE failed with status=%ld; " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | "defaulting to architected purge page-sizes.\n", status); |
| 352 | purge.mask = 0x115557000UL; |
| 353 | } |
| 354 | purge.max_bits = ia64_fls(purge.mask); |
| 355 | |
| 356 | ia64_get_ptce(&ptce_info); |
| 357 | local_cpu_data->ptce_base = ptce_info.base; |
| 358 | local_cpu_data->ptce_count[0] = ptce_info.count[0]; |
| 359 | local_cpu_data->ptce_count[1] = ptce_info.count[1]; |
| 360 | local_cpu_data->ptce_stride[0] = ptce_info.stride[0]; |
| 361 | local_cpu_data->ptce_stride[1] = ptce_info.stride[1]; |
| 362 | |
Chen, Kenneth W | 58cd908 | 2005-10-29 18:47:04 -0700 | [diff] [blame] | 363 | local_flush_tlb_all(); /* nuke left overs from bootstrapping... */ |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 364 | status = ia64_pal_vm_summary(&vm_info_1, &vm_info_2); |
| 365 | |
| 366 | if (status) { |
| 367 | printk(KERN_ERR "ia64_pal_vm_summary=%ld\n", status); |
| 368 | per_cpu(ia64_tr_num, cpu) = 8; |
| 369 | return; |
| 370 | } |
| 371 | per_cpu(ia64_tr_num, cpu) = vm_info_1.pal_vm_info_1_s.max_itr_entry+1; |
| 372 | if (per_cpu(ia64_tr_num, cpu) > |
| 373 | (vm_info_1.pal_vm_info_1_s.max_dtr_entry+1)) |
| 374 | per_cpu(ia64_tr_num, cpu) = |
| 375 | vm_info_1.pal_vm_info_1_s.max_dtr_entry+1; |
| 376 | if (per_cpu(ia64_tr_num, cpu) > IA64_TR_ALLOC_MAX) { |
Tony Luck | a9894a4 | 2008-10-17 13:47:53 -0700 | [diff] [blame] | 377 | static int justonce = 1; |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 378 | per_cpu(ia64_tr_num, cpu) = IA64_TR_ALLOC_MAX; |
Tony Luck | a9894a4 | 2008-10-17 13:47:53 -0700 | [diff] [blame] | 379 | if (justonce) { |
| 380 | justonce = 0; |
| 381 | printk(KERN_DEBUG "TR register number exceeds " |
| 382 | "IA64_TR_ALLOC_MAX!\n"); |
| 383 | } |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 384 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 386 | |
| 387 | /* |
| 388 | * is_tr_overlap |
| 389 | * |
| 390 | * Check overlap with inserted TRs. |
| 391 | */ |
| 392 | static int is_tr_overlap(struct ia64_tr_entry *p, u64 va, u64 log_size) |
| 393 | { |
| 394 | u64 tr_log_size; |
| 395 | u64 tr_end; |
| 396 | u64 va_rr = ia64_get_rr(va); |
| 397 | u64 va_rid = RR_TO_RID(va_rr); |
| 398 | u64 va_end = va + (1<<log_size) - 1; |
| 399 | |
| 400 | if (va_rid != RR_TO_RID(p->rr)) |
| 401 | return 0; |
| 402 | tr_log_size = (p->itir & 0xff) >> 2; |
| 403 | tr_end = p->ifa + (1<<tr_log_size) - 1; |
| 404 | |
| 405 | if (va > tr_end || p->ifa > va_end) |
| 406 | return 0; |
| 407 | return 1; |
| 408 | |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * ia64_insert_tr in virtual mode. Allocate a TR slot |
| 413 | * |
| 414 | * target_mask : 0x1 : itr, 0x2 : dtr, 0x3 : idtr |
| 415 | * |
| 416 | * va : virtual address. |
| 417 | * pte : pte entries inserted. |
| 418 | * log_size: range to be covered. |
| 419 | * |
| 420 | * Return value: <0 : error No. |
| 421 | * |
| 422 | * >=0 : slot number allocated for TR. |
| 423 | * Must be called with preemption disabled. |
| 424 | */ |
| 425 | int ia64_itr_entry(u64 target_mask, u64 va, u64 pte, u64 log_size) |
| 426 | { |
| 427 | int i, r; |
| 428 | unsigned long psr; |
| 429 | struct ia64_tr_entry *p; |
| 430 | int cpu = smp_processor_id(); |
| 431 | |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 432 | if (!ia64_idtrs[cpu]) { |
| 433 | ia64_idtrs[cpu] = kmalloc(2 * IA64_TR_ALLOC_MAX * |
| 434 | sizeof (struct ia64_tr_entry), GFP_KERNEL); |
| 435 | if (!ia64_idtrs[cpu]) |
| 436 | return -ENOMEM; |
| 437 | } |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 438 | r = -EINVAL; |
| 439 | /*Check overlap with existing TR entries*/ |
| 440 | if (target_mask & 0x1) { |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 441 | p = ia64_idtrs[cpu]; |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 442 | for (i = IA64_TR_ALLOC_BASE; i <= per_cpu(ia64_tr_used, cpu); |
| 443 | i++, p++) { |
| 444 | if (p->pte & 0x1) |
| 445 | if (is_tr_overlap(p, va, log_size)) { |
| 446 | printk(KERN_DEBUG "Overlapped Entry" |
| 447 | "Inserted for TR Reigster!!\n"); |
| 448 | goto out; |
| 449 | } |
| 450 | } |
| 451 | } |
| 452 | if (target_mask & 0x2) { |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 453 | p = ia64_idtrs[cpu] + IA64_TR_ALLOC_MAX; |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 454 | for (i = IA64_TR_ALLOC_BASE; i <= per_cpu(ia64_tr_used, cpu); |
| 455 | i++, p++) { |
| 456 | if (p->pte & 0x1) |
| 457 | if (is_tr_overlap(p, va, log_size)) { |
| 458 | printk(KERN_DEBUG "Overlapped Entry" |
| 459 | "Inserted for TR Reigster!!\n"); |
| 460 | goto out; |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | for (i = IA64_TR_ALLOC_BASE; i < per_cpu(ia64_tr_num, cpu); i++) { |
| 466 | switch (target_mask & 0x3) { |
| 467 | case 1: |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 468 | if (!((ia64_idtrs[cpu] + i)->pte & 0x1)) |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 469 | goto found; |
| 470 | continue; |
| 471 | case 2: |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 472 | if (!((ia64_idtrs[cpu] + IA64_TR_ALLOC_MAX + i)->pte & 0x1)) |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 473 | goto found; |
| 474 | continue; |
| 475 | case 3: |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 476 | if (!((ia64_idtrs[cpu] + i)->pte & 0x1) && |
| 477 | !((ia64_idtrs[cpu] + IA64_TR_ALLOC_MAX + i)->pte & 0x1)) |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 478 | goto found; |
| 479 | continue; |
| 480 | default: |
| 481 | r = -EINVAL; |
| 482 | goto out; |
| 483 | } |
| 484 | } |
| 485 | found: |
| 486 | if (i >= per_cpu(ia64_tr_num, cpu)) |
| 487 | return -EBUSY; |
| 488 | |
| 489 | /*Record tr info for mca hander use!*/ |
| 490 | if (i > per_cpu(ia64_tr_used, cpu)) |
| 491 | per_cpu(ia64_tr_used, cpu) = i; |
| 492 | |
| 493 | psr = ia64_clear_ic(); |
| 494 | if (target_mask & 0x1) { |
| 495 | ia64_itr(0x1, i, va, pte, log_size); |
| 496 | ia64_srlz_i(); |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 497 | p = ia64_idtrs[cpu] + i; |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 498 | p->ifa = va; |
| 499 | p->pte = pte; |
| 500 | p->itir = log_size << 2; |
| 501 | p->rr = ia64_get_rr(va); |
| 502 | } |
| 503 | if (target_mask & 0x2) { |
| 504 | ia64_itr(0x2, i, va, pte, log_size); |
| 505 | ia64_srlz_i(); |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 506 | p = ia64_idtrs[cpu] + IA64_TR_ALLOC_MAX + i; |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 507 | p->ifa = va; |
| 508 | p->pte = pte; |
| 509 | p->itir = log_size << 2; |
| 510 | p->rr = ia64_get_rr(va); |
| 511 | } |
| 512 | ia64_set_psr(psr); |
| 513 | r = i; |
| 514 | out: |
| 515 | return r; |
| 516 | } |
| 517 | EXPORT_SYMBOL_GPL(ia64_itr_entry); |
| 518 | |
| 519 | /* |
| 520 | * ia64_purge_tr |
| 521 | * |
| 522 | * target_mask: 0x1: purge itr, 0x2 : purge dtr, 0x3 purge idtr. |
| 523 | * slot: slot number to be freed. |
| 524 | * |
| 525 | * Must be called with preemption disabled. |
| 526 | */ |
| 527 | void ia64_ptr_entry(u64 target_mask, int slot) |
| 528 | { |
| 529 | int cpu = smp_processor_id(); |
| 530 | int i; |
| 531 | struct ia64_tr_entry *p; |
| 532 | |
| 533 | if (slot < IA64_TR_ALLOC_BASE || slot >= per_cpu(ia64_tr_num, cpu)) |
| 534 | return; |
| 535 | |
| 536 | if (target_mask & 0x1) { |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 537 | p = ia64_idtrs[cpu] + slot; |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 538 | if ((p->pte&0x1) && is_tr_overlap(p, p->ifa, p->itir>>2)) { |
| 539 | p->pte = 0; |
| 540 | ia64_ptr(0x1, p->ifa, p->itir>>2); |
| 541 | ia64_srlz_i(); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | if (target_mask & 0x2) { |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 546 | p = ia64_idtrs[cpu] + IA64_TR_ALLOC_MAX + slot; |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 547 | if ((p->pte & 0x1) && is_tr_overlap(p, p->ifa, p->itir>>2)) { |
| 548 | p->pte = 0; |
| 549 | ia64_ptr(0x2, p->ifa, p->itir>>2); |
| 550 | ia64_srlz_i(); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | for (i = per_cpu(ia64_tr_used, cpu); i >= IA64_TR_ALLOC_BASE; i--) { |
Tony Luck | 6c57a33 | 2010-01-07 16:10:57 -0800 | [diff] [blame] | 555 | if (((ia64_idtrs[cpu] + i)->pte & 0x1) || |
| 556 | ((ia64_idtrs[cpu] + IA64_TR_ALLOC_MAX + i)->pte & 0x1)) |
Xiantao Zhang | 9665189 | 2008-04-03 11:02:58 -0700 | [diff] [blame] | 557 | break; |
| 558 | } |
| 559 | per_cpu(ia64_tr_used, cpu) = i; |
| 560 | } |
| 561 | EXPORT_SYMBOL_GPL(ia64_ptr_entry); |