aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ia64/mm/tlb.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/ia64/mm/tlb.c')
-rw-r--r--arch/ia64/mm/tlb.c357
1 files changed, 342 insertions, 15 deletions
diff --git a/arch/ia64/mm/tlb.c b/arch/ia64/mm/tlb.c
index 655da240d13c..d52ec4e83409 100644
--- a/arch/ia64/mm/tlb.c
+++ b/arch/ia64/mm/tlb.c
@@ -11,6 +11,9 @@
11 * Rohit Seth <rohit.seth@intel.com> 11 * Rohit Seth <rohit.seth@intel.com>
12 * Ken Chen <kenneth.w.chen@intel.com> 12 * Ken Chen <kenneth.w.chen@intel.com>
13 * Christophe de Dinechin <ddd@hp.com>: Avoid ptc.e on memory allocation 13 * Christophe de Dinechin <ddd@hp.com>: Avoid ptc.e on memory allocation
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.
14 */ 17 */
15#include <linux/module.h> 18#include <linux/module.h>
16#include <linux/init.h> 19#include <linux/init.h>
@@ -26,6 +29,9 @@
26#include <asm/pal.h> 29#include <asm/pal.h>
27#include <asm/tlbflush.h> 30#include <asm/tlbflush.h>
28#include <asm/dma.h> 31#include <asm/dma.h>
32#include <asm/processor.h>
33#include <asm/sal.h>
34#include <asm/tlb.h>
29 35
30static struct { 36static struct {
31 unsigned long mask; /* mask of supported purge page-sizes */ 37 unsigned long mask; /* mask of supported purge page-sizes */
@@ -39,6 +45,10 @@ struct ia64_ctx ia64_ctx = {
39}; 45};
40 46
41DEFINE_PER_CPU(u8, ia64_need_tlb_flush); 47DEFINE_PER_CPU(u8, ia64_need_tlb_flush);
48DEFINE_PER_CPU(u8, ia64_tr_num); /*Number of TR slots in current processor*/
49DEFINE_PER_CPU(u8, ia64_tr_used); /*Max Slot number used by kernel*/
50
51struct ia64_tr_entry __per_cpu_idtrs[NR_CPUS][2][IA64_TR_ALLOC_MAX];
42 52
43/* 53/*
44 * Initializes the ia64_ctx.bitmap array based on max_ctx+1. 54 * Initializes the ia64_ctx.bitmap array based on max_ctx+1.
@@ -84,14 +94,140 @@ wrap_mmu_context (struct mm_struct *mm)
84 local_flush_tlb_all(); 94 local_flush_tlb_all();
85} 95}
86 96
97/*
98 * Implement "spinaphores" ... like counting semaphores, but they
99 * spin instead of sleeping. If there are ever any other users for
100 * this primitive it can be moved up to a spinaphore.h header.
101 */
102struct spinaphore {
103 atomic_t cur;
104};
105
106static inline void spinaphore_init(struct spinaphore *ss, int val)
107{
108 atomic_set(&ss->cur, val);
109}
110
111static inline void down_spin(struct spinaphore *ss)
112{
113 while (unlikely(!atomic_add_unless(&ss->cur, -1, 0)))
114 while (atomic_read(&ss->cur) == 0)
115 cpu_relax();
116}
117
118static inline void up_spin(struct spinaphore *ss)
119{
120 atomic_add(1, &ss->cur);
121}
122
123static struct spinaphore ptcg_sem;
124static u16 nptcg = 1;
125static int need_ptcg_sem = 1;
126static int toolatetochangeptcgsem = 0;
127
128/*
129 * Kernel parameter "nptcg=" overrides max number of concurrent global TLB
130 * purges which is reported from either PAL or SAL PALO.
131 *
132 * We don't have sanity checking for nptcg value. It's the user's responsibility
133 * for valid nptcg value on the platform. Otherwise, kernel may hang in some
134 * cases.
135 */
136static int __init
137set_nptcg(char *str)
138{
139 int value = 0;
140
141 get_option(&str, &value);
142 setup_ptcg_sem(value, NPTCG_FROM_KERNEL_PARAMETER);
143
144 return 1;
145}
146
147__setup("nptcg=", set_nptcg);
148
149/*
150 * Maximum number of simultaneous ptc.g purges in the system can
151 * be defined by PAL_VM_SUMMARY (in which case we should take
152 * the smallest value for any cpu in the system) or by the PAL
153 * override table (in which case we should ignore the value from
154 * PAL_VM_SUMMARY).
155 *
156 * Kernel parameter "nptcg=" overrides maximum number of simultanesous ptc.g
157 * purges defined in either PAL_VM_SUMMARY or PAL override table. In this case,
158 * we should ignore the value from either PAL_VM_SUMMARY or PAL override table.
159 *
160 * Complicating the logic here is the fact that num_possible_cpus()
161 * isn't fully setup until we start bringing cpus online.
162 */
163void
164setup_ptcg_sem(int max_purges, int nptcg_from)
165{
166 static int kp_override;
167 static int palo_override;
168 static int firstcpu = 1;
169
170 if (toolatetochangeptcgsem) {
171 BUG_ON(max_purges < nptcg);
172 return;
173 }
174
175 if (nptcg_from == NPTCG_FROM_KERNEL_PARAMETER) {
176 kp_override = 1;
177 nptcg = max_purges;
178 goto resetsema;
179 }
180 if (kp_override) {
181 need_ptcg_sem = num_possible_cpus() > nptcg;
182 return;
183 }
184
185 if (nptcg_from == NPTCG_FROM_PALO) {
186 palo_override = 1;
187
188 /* In PALO max_purges == 0 really means it! */
189 if (max_purges == 0)
190 panic("Whoa! Platform does not support global TLB purges.\n");
191 nptcg = max_purges;
192 if (nptcg == PALO_MAX_TLB_PURGES) {
193 need_ptcg_sem = 0;
194 return;
195 }
196 goto resetsema;
197 }
198 if (palo_override) {
199 if (nptcg != PALO_MAX_TLB_PURGES)
200 need_ptcg_sem = (num_possible_cpus() > nptcg);
201 return;
202 }
203
204 /* In PAL_VM_SUMMARY max_purges == 0 actually means 1 */
205 if (max_purges == 0) max_purges = 1;
206
207 if (firstcpu) {
208 nptcg = max_purges;
209 firstcpu = 0;
210 }
211 if (max_purges < nptcg)
212 nptcg = max_purges;
213 if (nptcg == PAL_MAX_PURGES) {
214 need_ptcg_sem = 0;
215 return;
216 } else
217 need_ptcg_sem = (num_possible_cpus() > nptcg);
218
219resetsema:
220 spinaphore_init(&ptcg_sem, max_purges);
221}
222
87void 223void
88ia64_global_tlb_purge (struct mm_struct *mm, unsigned long start, 224ia64_global_tlb_purge (struct mm_struct *mm, unsigned long start,
89 unsigned long end, unsigned long nbits) 225 unsigned long end, unsigned long nbits)
90{ 226{
91 static DEFINE_SPINLOCK(ptcg_lock);
92
93 struct mm_struct *active_mm = current->active_mm; 227 struct mm_struct *active_mm = current->active_mm;
94 228
229 toolatetochangeptcgsem = 1;
230
95 if (mm != active_mm) { 231 if (mm != active_mm) {
96 /* Restore region IDs for mm */ 232 /* Restore region IDs for mm */
97 if (mm && active_mm) { 233 if (mm && active_mm) {
@@ -102,19 +238,20 @@ ia64_global_tlb_purge (struct mm_struct *mm, unsigned long start,
102 } 238 }
103 } 239 }
104 240
105 /* HW requires global serialization of ptc.ga. */ 241 if (need_ptcg_sem)
106 spin_lock(&ptcg_lock); 242 down_spin(&ptcg_sem);
107 { 243
108 do { 244 do {
109 /* 245 /*
110 * Flush ALAT entries also. 246 * Flush ALAT entries also.
111 */ 247 */
112 ia64_ptcga(start, (nbits<<2)); 248 ia64_ptcga(start, (nbits << 2));
113 ia64_srlz_i(); 249 ia64_srlz_i();
114 start += (1UL << nbits); 250 start += (1UL << nbits);
115 } while (start < end); 251 } while (start < end);
116 } 252
117 spin_unlock(&ptcg_lock); 253 if (need_ptcg_sem)
254 up_spin(&ptcg_sem);
118 255
119 if (mm != active_mm) { 256 if (mm != active_mm) {
120 activate_context(active_mm); 257 activate_context(active_mm);
@@ -190,6 +327,9 @@ ia64_tlb_init (void)
190 ia64_ptce_info_t uninitialized_var(ptce_info); /* GCC be quiet */ 327 ia64_ptce_info_t uninitialized_var(ptce_info); /* GCC be quiet */
191 unsigned long tr_pgbits; 328 unsigned long tr_pgbits;
192 long status; 329 long status;
330 pal_vm_info_1_u_t vm_info_1;
331 pal_vm_info_2_u_t vm_info_2;
332 int cpu = smp_processor_id();
193 333
194 if ((status = ia64_pal_vm_page_size(&tr_pgbits, &purge.mask)) != 0) { 334 if ((status = ia64_pal_vm_page_size(&tr_pgbits, &purge.mask)) != 0) {
195 printk(KERN_ERR "PAL_VM_PAGE_SIZE failed with status=%ld; " 335 printk(KERN_ERR "PAL_VM_PAGE_SIZE failed with status=%ld; "
@@ -206,4 +346,191 @@ ia64_tlb_init (void)
206 local_cpu_data->ptce_stride[1] = ptce_info.stride[1]; 346 local_cpu_data->ptce_stride[1] = ptce_info.stride[1];
207 347
208 local_flush_tlb_all(); /* nuke left overs from bootstrapping... */ 348 local_flush_tlb_all(); /* nuke left overs from bootstrapping... */
349 status = ia64_pal_vm_summary(&vm_info_1, &vm_info_2);
350
351 if (status) {
352 printk(KERN_ERR "ia64_pal_vm_summary=%ld\n", status);
353 per_cpu(ia64_tr_num, cpu) = 8;
354 return;
355 }
356 per_cpu(ia64_tr_num, cpu) = vm_info_1.pal_vm_info_1_s.max_itr_entry+1;
357 if (per_cpu(ia64_tr_num, cpu) >
358 (vm_info_1.pal_vm_info_1_s.max_dtr_entry+1))
359 per_cpu(ia64_tr_num, cpu) =
360 vm_info_1.pal_vm_info_1_s.max_dtr_entry+1;
361 if (per_cpu(ia64_tr_num, cpu) > IA64_TR_ALLOC_MAX) {
362 per_cpu(ia64_tr_num, cpu) = IA64_TR_ALLOC_MAX;
363 printk(KERN_DEBUG "TR register number exceeds IA64_TR_ALLOC_MAX!"
364 "IA64_TR_ALLOC_MAX should be extended\n");
365 }
366}
367
368/*
369 * is_tr_overlap
370 *
371 * Check overlap with inserted TRs.
372 */
373static int is_tr_overlap(struct ia64_tr_entry *p, u64 va, u64 log_size)
374{
375 u64 tr_log_size;
376 u64 tr_end;
377 u64 va_rr = ia64_get_rr(va);
378 u64 va_rid = RR_TO_RID(va_rr);
379 u64 va_end = va + (1<<log_size) - 1;
380
381 if (va_rid != RR_TO_RID(p->rr))
382 return 0;
383 tr_log_size = (p->itir & 0xff) >> 2;
384 tr_end = p->ifa + (1<<tr_log_size) - 1;
385
386 if (va > tr_end || p->ifa > va_end)
387 return 0;
388 return 1;
389
390}
391
392/*
393 * ia64_insert_tr in virtual mode. Allocate a TR slot
394 *
395 * target_mask : 0x1 : itr, 0x2 : dtr, 0x3 : idtr
396 *
397 * va : virtual address.
398 * pte : pte entries inserted.
399 * log_size: range to be covered.
400 *
401 * Return value: <0 : error No.
402 *
403 * >=0 : slot number allocated for TR.
404 * Must be called with preemption disabled.
405 */
406int ia64_itr_entry(u64 target_mask, u64 va, u64 pte, u64 log_size)
407{
408 int i, r;
409 unsigned long psr;
410 struct ia64_tr_entry *p;
411 int cpu = smp_processor_id();
412
413 r = -EINVAL;
414 /*Check overlap with existing TR entries*/
415 if (target_mask & 0x1) {
416 p = &__per_cpu_idtrs[cpu][0][0];
417 for (i = IA64_TR_ALLOC_BASE; i <= per_cpu(ia64_tr_used, cpu);
418 i++, p++) {
419 if (p->pte & 0x1)
420 if (is_tr_overlap(p, va, log_size)) {
421 printk(KERN_DEBUG "Overlapped Entry"
422 "Inserted for TR Reigster!!\n");
423 goto out;
424 }
425 }
426 }
427 if (target_mask & 0x2) {
428 p = &__per_cpu_idtrs[cpu][1][0];
429 for (i = IA64_TR_ALLOC_BASE; i <= per_cpu(ia64_tr_used, cpu);
430 i++, p++) {
431 if (p->pte & 0x1)
432 if (is_tr_overlap(p, va, log_size)) {
433 printk(KERN_DEBUG "Overlapped Entry"
434 "Inserted for TR Reigster!!\n");
435 goto out;
436 }
437 }
438 }
439
440 for (i = IA64_TR_ALLOC_BASE; i < per_cpu(ia64_tr_num, cpu); i++) {
441 switch (target_mask & 0x3) {
442 case 1:
443 if (!(__per_cpu_idtrs[cpu][0][i].pte & 0x1))
444 goto found;
445 continue;
446 case 2:
447 if (!(__per_cpu_idtrs[cpu][1][i].pte & 0x1))
448 goto found;
449 continue;
450 case 3:
451 if (!(__per_cpu_idtrs[cpu][0][i].pte & 0x1) &&
452 !(__per_cpu_idtrs[cpu][1][i].pte & 0x1))
453 goto found;
454 continue;
455 default:
456 r = -EINVAL;
457 goto out;
458 }
459 }
460found:
461 if (i >= per_cpu(ia64_tr_num, cpu))
462 return -EBUSY;
463
464 /*Record tr info for mca hander use!*/
465 if (i > per_cpu(ia64_tr_used, cpu))
466 per_cpu(ia64_tr_used, cpu) = i;
467
468 psr = ia64_clear_ic();
469 if (target_mask & 0x1) {
470 ia64_itr(0x1, i, va, pte, log_size);
471 ia64_srlz_i();
472 p = &__per_cpu_idtrs[cpu][0][i];
473 p->ifa = va;
474 p->pte = pte;
475 p->itir = log_size << 2;
476 p->rr = ia64_get_rr(va);
477 }
478 if (target_mask & 0x2) {
479 ia64_itr(0x2, i, va, pte, log_size);
480 ia64_srlz_i();
481 p = &__per_cpu_idtrs[cpu][1][i];
482 p->ifa = va;
483 p->pte = pte;
484 p->itir = log_size << 2;
485 p->rr = ia64_get_rr(va);
486 }
487 ia64_set_psr(psr);
488 r = i;
489out:
490 return r;
491}
492EXPORT_SYMBOL_GPL(ia64_itr_entry);
493
494/*
495 * ia64_purge_tr
496 *
497 * target_mask: 0x1: purge itr, 0x2 : purge dtr, 0x3 purge idtr.
498 * slot: slot number to be freed.
499 *
500 * Must be called with preemption disabled.
501 */
502void ia64_ptr_entry(u64 target_mask, int slot)
503{
504 int cpu = smp_processor_id();
505 int i;
506 struct ia64_tr_entry *p;
507
508 if (slot < IA64_TR_ALLOC_BASE || slot >= per_cpu(ia64_tr_num, cpu))
509 return;
510
511 if (target_mask & 0x1) {
512 p = &__per_cpu_idtrs[cpu][0][slot];
513 if ((p->pte&0x1) && is_tr_overlap(p, p->ifa, p->itir>>2)) {
514 p->pte = 0;
515 ia64_ptr(0x1, p->ifa, p->itir>>2);
516 ia64_srlz_i();
517 }
518 }
519
520 if (target_mask & 0x2) {
521 p = &__per_cpu_idtrs[cpu][1][slot];
522 if ((p->pte & 0x1) && is_tr_overlap(p, p->ifa, p->itir>>2)) {
523 p->pte = 0;
524 ia64_ptr(0x2, p->ifa, p->itir>>2);
525 ia64_srlz_i();
526 }
527 }
528
529 for (i = per_cpu(ia64_tr_used, cpu); i >= IA64_TR_ALLOC_BASE; i--) {
530 if ((__per_cpu_idtrs[cpu][0][i].pte & 0x1) ||
531 (__per_cpu_idtrs[cpu][1][i].pte & 0x1))
532 break;
533 }
534 per_cpu(ia64_tr_used, cpu) = i;
209} 535}
536EXPORT_SYMBOL_GPL(ia64_ptr_entry);