]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/mips/kernel/smtc.c
[MIPS] SMTC: Move MIPS_CPU_IPI_IRQ definition into header.
[linux-2.6-omap-h63xx.git] / arch / mips / kernel / smtc.c
1 /* Copyright (C) 2004 Mips Technologies, Inc */
2
3 #include <linux/kernel.h>
4 #include <linux/sched.h>
5 #include <linux/cpumask.h>
6 #include <linux/interrupt.h>
7 #include <linux/kernel_stat.h>
8 #include <linux/module.h>
9
10 #include <asm/cpu.h>
11 #include <asm/processor.h>
12 #include <asm/atomic.h>
13 #include <asm/system.h>
14 #include <asm/hardirq.h>
15 #include <asm/hazards.h>
16 #include <asm/irq.h>
17 #include <asm/mmu_context.h>
18 #include <asm/smp.h>
19 #include <asm/mipsregs.h>
20 #include <asm/cacheflush.h>
21 #include <asm/time.h>
22 #include <asm/addrspace.h>
23 #include <asm/smtc.h>
24 #include <asm/smtc_ipi.h>
25 #include <asm/smtc_proc.h>
26
27 /*
28  * This file should be built into the kernel only if CONFIG_MIPS_MT_SMTC is set.
29  */
30
31 #define LOCK_MT_PRA() \
32         local_irq_save(flags); \
33         mtflags = dmt()
34
35 #define UNLOCK_MT_PRA() \
36         emt(mtflags); \
37         local_irq_restore(flags)
38
39 #define LOCK_CORE_PRA() \
40         local_irq_save(flags); \
41         mtflags = dvpe()
42
43 #define UNLOCK_CORE_PRA() \
44         evpe(mtflags); \
45         local_irq_restore(flags)
46
47 /*
48  * Data structures purely associated with SMTC parallelism
49  */
50
51
52 /*
53  * Table for tracking ASIDs whose lifetime is prolonged.
54  */
55
56 asiduse smtc_live_asid[MAX_SMTC_TLBS][MAX_SMTC_ASIDS];
57
58 /*
59  * Clock interrupt "latch" buffers, per "CPU"
60  */
61
62 unsigned int ipi_timer_latch[NR_CPUS];
63
64 /*
65  * Number of InterProcessor Interupt (IPI) message buffers to allocate
66  */
67
68 #define IPIBUF_PER_CPU 4
69
70 static struct smtc_ipi_q IPIQ[NR_CPUS];
71 static struct smtc_ipi_q freeIPIq;
72
73
74 /* Forward declarations */
75
76 void ipi_decode(struct smtc_ipi *);
77 static void post_direct_ipi(int cpu, struct smtc_ipi *pipi);
78 static void setup_cross_vpe_interrupts(unsigned int nvpe);
79 void init_smtc_stats(void);
80
81 /* Global SMTC Status */
82
83 unsigned int smtc_status = 0;
84
85 /* Boot command line configuration overrides */
86
87 static int ipibuffers = 0;
88 static int nostlb = 0;
89 static int asidmask = 0;
90 unsigned long smtc_asid_mask = 0xff;
91
92 static int __init ipibufs(char *str)
93 {
94         get_option(&str, &ipibuffers);
95         return 1;
96 }
97
98 static int __init stlb_disable(char *s)
99 {
100         nostlb = 1;
101         return 1;
102 }
103
104 static int __init asidmask_set(char *str)
105 {
106         get_option(&str, &asidmask);
107         switch (asidmask) {
108         case 0x1:
109         case 0x3:
110         case 0x7:
111         case 0xf:
112         case 0x1f:
113         case 0x3f:
114         case 0x7f:
115         case 0xff:
116                 smtc_asid_mask = (unsigned long)asidmask;
117                 break;
118         default:
119                 printk("ILLEGAL ASID mask 0x%x from command line\n", asidmask);
120         }
121         return 1;
122 }
123
124 __setup("ipibufs=", ipibufs);
125 __setup("nostlb", stlb_disable);
126 __setup("asidmask=", asidmask_set);
127
128 #ifdef CONFIG_SMTC_IDLE_HOOK_DEBUG
129
130 static int hang_trig = 0;
131
132 static int __init hangtrig_enable(char *s)
133 {
134         hang_trig = 1;
135         return 1;
136 }
137
138
139 __setup("hangtrig", hangtrig_enable);
140
141 #define DEFAULT_BLOCKED_IPI_LIMIT 32
142
143 static int timerq_limit = DEFAULT_BLOCKED_IPI_LIMIT;
144
145 static int __init tintq(char *str)
146 {
147         get_option(&str, &timerq_limit);
148         return 1;
149 }
150
151 __setup("tintq=", tintq);
152
153 static int imstuckcount[2][8];
154 /* vpemask represents IM/IE bits of per-VPE Status registers, low-to-high */
155 static int vpemask[2][8] = {
156         {0, 0, 1, 0, 0, 0, 0, 1},
157         {0, 0, 0, 0, 0, 0, 0, 1}
158 };
159 int tcnoprog[NR_CPUS];
160 static atomic_t idle_hook_initialized = {0};
161 static int clock_hang_reported[NR_CPUS];
162
163 #endif /* CONFIG_SMTC_IDLE_HOOK_DEBUG */
164
165 /* Initialize shared TLB - the should probably migrate to smtc_setup_cpus() */
166
167 void __init sanitize_tlb_entries(void)
168 {
169         printk("Deprecated sanitize_tlb_entries() invoked\n");
170 }
171
172
173 /*
174  * Configure shared TLB - VPC configuration bit must be set by caller
175  */
176
177 static void smtc_configure_tlb(void)
178 {
179         int i,tlbsiz,vpes;
180         unsigned long mvpconf0;
181         unsigned long config1val;
182
183         /* Set up ASID preservation table */
184         for (vpes=0; vpes<MAX_SMTC_TLBS; vpes++) {
185             for(i = 0; i < MAX_SMTC_ASIDS; i++) {
186                 smtc_live_asid[vpes][i] = 0;
187             }
188         }
189         mvpconf0 = read_c0_mvpconf0();
190
191         if ((vpes = ((mvpconf0 & MVPCONF0_PVPE)
192                         >> MVPCONF0_PVPE_SHIFT) + 1) > 1) {
193             /* If we have multiple VPEs, try to share the TLB */
194             if ((mvpconf0 & MVPCONF0_TLBS) && !nostlb) {
195                 /*
196                  * If TLB sizing is programmable, shared TLB
197                  * size is the total available complement.
198                  * Otherwise, we have to take the sum of all
199                  * static VPE TLB entries.
200                  */
201                 if ((tlbsiz = ((mvpconf0 & MVPCONF0_PTLBE)
202                                 >> MVPCONF0_PTLBE_SHIFT)) == 0) {
203                     /*
204                      * If there's more than one VPE, there had better
205                      * be more than one TC, because we need one to bind
206                      * to each VPE in turn to be able to read
207                      * its configuration state!
208                      */
209                     settc(1);
210                     /* Stop the TC from doing anything foolish */
211                     write_tc_c0_tchalt(TCHALT_H);
212                     mips_ihb();
213                     /* No need to un-Halt - that happens later anyway */
214                     for (i=0; i < vpes; i++) {
215                         write_tc_c0_tcbind(i);
216                         /*
217                          * To be 100% sure we're really getting the right
218                          * information, we exit the configuration state
219                          * and do an IHB after each rebinding.
220                          */
221                         write_c0_mvpcontrol(
222                                 read_c0_mvpcontrol() & ~ MVPCONTROL_VPC );
223                         mips_ihb();
224                         /*
225                          * Only count if the MMU Type indicated is TLB
226                          */
227                         if (((read_vpe_c0_config() & MIPS_CONF_MT) >> 7) == 1) {
228                                 config1val = read_vpe_c0_config1();
229                                 tlbsiz += ((config1val >> 25) & 0x3f) + 1;
230                         }
231
232                         /* Put core back in configuration state */
233                         write_c0_mvpcontrol(
234                                 read_c0_mvpcontrol() | MVPCONTROL_VPC );
235                         mips_ihb();
236                     }
237                 }
238                 write_c0_mvpcontrol(read_c0_mvpcontrol() | MVPCONTROL_STLB);
239                 ehb();
240
241                 /*
242                  * Setup kernel data structures to use software total,
243                  * rather than read the per-VPE Config1 value. The values
244                  * for "CPU 0" gets copied to all the other CPUs as part
245                  * of their initialization in smtc_cpu_setup().
246                  */
247
248                 /* MIPS32 limits TLB indices to 64 */
249                 if (tlbsiz > 64)
250                         tlbsiz = 64;
251                 cpu_data[0].tlbsize = current_cpu_data.tlbsize = tlbsiz;
252                 smtc_status |= SMTC_TLB_SHARED;
253                 local_flush_tlb_all();
254
255                 printk("TLB of %d entry pairs shared by %d VPEs\n",
256                         tlbsiz, vpes);
257             } else {
258                 printk("WARNING: TLB Not Sharable on SMTC Boot!\n");
259             }
260         }
261 }
262
263
264 /*
265  * Incrementally build the CPU map out of constituent MIPS MT cores,
266  * using the specified available VPEs and TCs.  Plaform code needs
267  * to ensure that each MIPS MT core invokes this routine on reset,
268  * one at a time(!).
269  *
270  * This version of the build_cpu_map and prepare_cpus routines assumes
271  * that *all* TCs of a MIPS MT core will be used for Linux, and that
272  * they will be spread across *all* available VPEs (to minimise the
273  * loss of efficiency due to exception service serialization).
274  * An improved version would pick up configuration information and
275  * possibly leave some TCs/VPEs as "slave" processors.
276  *
277  * Use c0_MVPConf0 to find out how many TCs are available, setting up
278  * phys_cpu_present_map and the logical/physical mappings.
279  */
280
281 int __init mipsmt_build_cpu_map(int start_cpu_slot)
282 {
283         int i, ntcs;
284
285         /*
286          * The CPU map isn't actually used for anything at this point,
287          * so it's not clear what else we should do apart from set
288          * everything up so that "logical" = "physical".
289          */
290         ntcs = ((read_c0_mvpconf0() & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
291         for (i=start_cpu_slot; i<NR_CPUS && i<ntcs; i++) {
292                 cpu_set(i, phys_cpu_present_map);
293                 __cpu_number_map[i] = i;
294                 __cpu_logical_map[i] = i;
295         }
296         /* Initialize map of CPUs with FPUs */
297         cpus_clear(mt_fpu_cpumask);
298
299         /* One of those TC's is the one booting, and not a secondary... */
300         printk("%i available secondary CPU TC(s)\n", i - 1);
301
302         return i;
303 }
304
305 /*
306  * Common setup before any secondaries are started
307  * Make sure all CPU's are in a sensible state before we boot any of the
308  * secondaries.
309  *
310  * For MIPS MT "SMTC" operation, we set up all TCs, spread as evenly
311  * as possible across the available VPEs.
312  */
313
314 static void smtc_tc_setup(int vpe, int tc, int cpu)
315 {
316         settc(tc);
317         write_tc_c0_tchalt(TCHALT_H);
318         mips_ihb();
319         write_tc_c0_tcstatus((read_tc_c0_tcstatus()
320                         & ~(TCSTATUS_TKSU | TCSTATUS_DA | TCSTATUS_IXMT))
321                         | TCSTATUS_A);
322         write_tc_c0_tccontext(0);
323         /* Bind tc to vpe */
324         write_tc_c0_tcbind(vpe);
325         /* In general, all TCs should have the same cpu_data indications */
326         memcpy(&cpu_data[cpu], &cpu_data[0], sizeof(struct cpuinfo_mips));
327         /* For 34Kf, start with TC/CPU 0 as sole owner of single FPU context */
328         if (cpu_data[0].cputype == CPU_34K)
329                 cpu_data[cpu].options &= ~MIPS_CPU_FPU;
330         cpu_data[cpu].vpe_id = vpe;
331         cpu_data[cpu].tc_id = tc;
332 }
333
334
335 void mipsmt_prepare_cpus(void)
336 {
337         int i, vpe, tc, ntc, nvpe, tcpervpe, slop, cpu;
338         unsigned long flags;
339         unsigned long val;
340         int nipi;
341         struct smtc_ipi *pipi;
342
343         /* disable interrupts so we can disable MT */
344         local_irq_save(flags);
345         /* disable MT so we can configure */
346         dvpe();
347         dmt();
348
349         spin_lock_init(&freeIPIq.lock);
350
351         /*
352          * We probably don't have as many VPEs as we do SMP "CPUs",
353          * but it's possible - and in any case we'll never use more!
354          */
355         for (i=0; i<NR_CPUS; i++) {
356                 IPIQ[i].head = IPIQ[i].tail = NULL;
357                 spin_lock_init(&IPIQ[i].lock);
358                 IPIQ[i].depth = 0;
359                 ipi_timer_latch[i] = 0;
360         }
361
362         /* cpu_data index starts at zero */
363         cpu = 0;
364         cpu_data[cpu].vpe_id = 0;
365         cpu_data[cpu].tc_id = 0;
366         cpu++;
367
368         /* Report on boot-time options */
369         mips_mt_set_cpuoptions ();
370         if (vpelimit > 0)
371                 printk("Limit of %d VPEs set\n", vpelimit);
372         if (tclimit > 0)
373                 printk("Limit of %d TCs set\n", tclimit);
374         if (nostlb) {
375                 printk("Shared TLB Use Inhibited - UNSAFE for Multi-VPE Operation\n");
376         }
377         if (asidmask)
378                 printk("ASID mask value override to 0x%x\n", asidmask);
379
380         /* Temporary */
381 #ifdef CONFIG_SMTC_IDLE_HOOK_DEBUG
382         if (hang_trig)
383                 printk("Logic Analyser Trigger on suspected TC hang\n");
384 #endif /* CONFIG_SMTC_IDLE_HOOK_DEBUG */
385
386         /* Put MVPE's into 'configuration state' */
387         write_c0_mvpcontrol( read_c0_mvpcontrol() | MVPCONTROL_VPC );
388
389         val = read_c0_mvpconf0();
390         nvpe = ((val & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
391         if (vpelimit > 0 && nvpe > vpelimit)
392                 nvpe = vpelimit;
393         ntc = ((val & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
394         if (ntc > NR_CPUS)
395                 ntc = NR_CPUS;
396         if (tclimit > 0 && ntc > tclimit)
397                 ntc = tclimit;
398         tcpervpe = ntc / nvpe;
399         slop = ntc % nvpe;      /* Residual TCs, < NVPE */
400
401         /* Set up shared TLB */
402         smtc_configure_tlb();
403
404         for (tc = 0, vpe = 0 ; (vpe < nvpe) && (tc < ntc) ; vpe++) {
405                 /*
406                  * Set the MVP bits.
407                  */
408                 settc(tc);
409                 write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() | VPECONF0_MVP);
410                 if (vpe != 0)
411                         printk(", ");
412                 printk("VPE %d: TC", vpe);
413                 for (i = 0; i < tcpervpe; i++) {
414                         /*
415                          * TC 0 is bound to VPE 0 at reset,
416                          * and is presumably executing this
417                          * code.  Leave it alone!
418                          */
419                         if (tc != 0) {
420                                 smtc_tc_setup(vpe,tc, cpu);
421                                 cpu++;
422                         }
423                         printk(" %d", tc);
424                         tc++;
425                 }
426                 if (slop) {
427                         if (tc != 0) {
428                                 smtc_tc_setup(vpe,tc, cpu);
429                                 cpu++;
430                         }
431                         printk(" %d", tc);
432                         tc++;
433                         slop--;
434                 }
435                 if (vpe != 0) {
436                         /*
437                          * Clear any stale software interrupts from VPE's Cause
438                          */
439                         write_vpe_c0_cause(0);
440
441                         /*
442                          * Clear ERL/EXL of VPEs other than 0
443                          * and set restricted interrupt enable/mask.
444                          */
445                         write_vpe_c0_status((read_vpe_c0_status()
446                                 & ~(ST0_BEV | ST0_ERL | ST0_EXL | ST0_IM))
447                                 | (STATUSF_IP0 | STATUSF_IP1 | STATUSF_IP7
448                                 | ST0_IE));
449                         /*
450                          * set config to be the same as vpe0,
451                          *  particularly kseg0 coherency alg
452                          */
453                         write_vpe_c0_config(read_c0_config());
454                         /* Clear any pending timer interrupt */
455                         write_vpe_c0_compare(0);
456                         /* Propagate Config7 */
457                         write_vpe_c0_config7(read_c0_config7());
458                         write_vpe_c0_count(read_c0_count());
459                 }
460                 /* enable multi-threading within VPE */
461                 write_vpe_c0_vpecontrol(read_vpe_c0_vpecontrol() | VPECONTROL_TE);
462                 /* enable the VPE */
463                 write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() | VPECONF0_VPA);
464         }
465
466         /*
467          * Pull any physically present but unused TCs out of circulation.
468          */
469         while (tc < (((val & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1)) {
470                 cpu_clear(tc, phys_cpu_present_map);
471                 cpu_clear(tc, cpu_present_map);
472                 tc++;
473         }
474
475         /* release config state */
476         write_c0_mvpcontrol( read_c0_mvpcontrol() & ~ MVPCONTROL_VPC );
477
478         printk("\n");
479
480         /* Set up coprocessor affinity CPU mask(s) */
481
482         for (tc = 0; tc < ntc; tc++) {
483                 if (cpu_data[tc].options & MIPS_CPU_FPU)
484                         cpu_set(tc, mt_fpu_cpumask);
485         }
486
487         /* set up ipi interrupts... */
488
489         /* If we have multiple VPEs running, set up the cross-VPE interrupt */
490
491         setup_cross_vpe_interrupts(nvpe);
492
493         /* Set up queue of free IPI "messages". */
494         nipi = NR_CPUS * IPIBUF_PER_CPU;
495         if (ipibuffers > 0)
496                 nipi = ipibuffers;
497
498         pipi = kmalloc(nipi *sizeof(struct smtc_ipi), GFP_KERNEL);
499         if (pipi == NULL)
500                 panic("kmalloc of IPI message buffers failed\n");
501         else
502                 printk("IPI buffer pool of %d buffers\n", nipi);
503         for (i = 0; i < nipi; i++) {
504                 smtc_ipi_nq(&freeIPIq, pipi);
505                 pipi++;
506         }
507
508         /* Arm multithreading and enable other VPEs - but all TCs are Halted */
509         emt(EMT_ENABLE);
510         evpe(EVPE_ENABLE);
511         local_irq_restore(flags);
512         /* Initialize SMTC /proc statistics/diagnostics */
513         init_smtc_stats();
514 }
515
516
517 /*
518  * Setup the PC, SP, and GP of a secondary processor and start it
519  * running!
520  * smp_bootstrap is the place to resume from
521  * __KSTK_TOS(idle) is apparently the stack pointer
522  * (unsigned long)idle->thread_info the gp
523  *
524  */
525 void __cpuinit smtc_boot_secondary(int cpu, struct task_struct *idle)
526 {
527         extern u32 kernelsp[NR_CPUS];
528         long flags;
529         int mtflags;
530
531         LOCK_MT_PRA();
532         if (cpu_data[cpu].vpe_id != cpu_data[smp_processor_id()].vpe_id) {
533                 dvpe();
534         }
535         settc(cpu_data[cpu].tc_id);
536
537         /* pc */
538         write_tc_c0_tcrestart((unsigned long)&smp_bootstrap);
539
540         /* stack pointer */
541         kernelsp[cpu] = __KSTK_TOS(idle);
542         write_tc_gpr_sp(__KSTK_TOS(idle));
543
544         /* global pointer */
545         write_tc_gpr_gp((unsigned long)task_thread_info(idle));
546
547         smtc_status |= SMTC_MTC_ACTIVE;
548         write_tc_c0_tchalt(0);
549         if (cpu_data[cpu].vpe_id != cpu_data[smp_processor_id()].vpe_id) {
550                 evpe(EVPE_ENABLE);
551         }
552         UNLOCK_MT_PRA();
553 }
554
555 void smtc_init_secondary(void)
556 {
557         /*
558          * Start timer on secondary VPEs if necessary.
559          * plat_timer_setup has already have been invoked by init/main
560          * on "boot" TC.  Like per_cpu_trap_init() hack, this assumes that
561          * SMTC init code assigns TCs consdecutively and in ascending order
562          * to across available VPEs.
563          */
564         if (((read_c0_tcbind() & TCBIND_CURTC) != 0) &&
565             ((read_c0_tcbind() & TCBIND_CURVPE)
566             != cpu_data[smp_processor_id() - 1].vpe_id)){
567                 write_c0_compare (read_c0_count() + mips_hpt_frequency/HZ);
568         }
569
570         local_irq_enable();
571 }
572
573 void smtc_smp_finish(void)
574 {
575         printk("TC %d going on-line as CPU %d\n",
576                 cpu_data[smp_processor_id()].tc_id, smp_processor_id());
577 }
578
579 void smtc_cpus_done(void)
580 {
581 }
582
583 /*
584  * Support for SMTC-optimized driver IRQ registration
585  */
586
587 /*
588  * SMTC Kernel needs to manipulate low-level CPU interrupt mask
589  * in do_IRQ. These are passed in setup_irq_smtc() and stored
590  * in this table.
591  */
592
593 int setup_irq_smtc(unsigned int irq, struct irqaction * new,
594                         unsigned long hwmask)
595 {
596 #ifdef CONFIG_SMTC_IDLE_HOOK_DEBUG
597         unsigned int vpe = current_cpu_data.vpe_id;
598
599         vpemask[vpe][irq - MIPS_CPU_IRQ_BASE] = 1;
600 #endif
601         irq_hwmask[irq] = hwmask;
602
603         return setup_irq(irq, new);
604 }
605
606 /*
607  * IPI model for SMTC is tricky, because interrupts aren't TC-specific.
608  * Within a VPE one TC can interrupt another by different approaches.
609  * The easiest to get right would probably be to make all TCs except
610  * the target IXMT and set a software interrupt, but an IXMT-based
611  * scheme requires that a handler must run before a new IPI could
612  * be sent, which would break the "broadcast" loops in MIPS MT.
613  * A more gonzo approach within a VPE is to halt the TC, extract
614  * its Restart, Status, and a couple of GPRs, and program the Restart
615  * address to emulate an interrupt.
616  *
617  * Within a VPE, one can be confident that the target TC isn't in
618  * a critical EXL state when halted, since the write to the Halt
619  * register could not have issued on the writing thread if the
620  * halting thread had EXL set. So k0 and k1 of the target TC
621  * can be used by the injection code.  Across VPEs, one can't
622  * be certain that the target TC isn't in a critical exception
623  * state. So we try a two-step process of sending a software
624  * interrupt to the target VPE, which either handles the event
625  * itself (if it was the target) or injects the event within
626  * the VPE.
627  */
628
629 static void smtc_ipi_qdump(void)
630 {
631         int i;
632
633         for (i = 0; i < NR_CPUS ;i++) {
634                 printk("IPIQ[%d]: head = 0x%x, tail = 0x%x, depth = %d\n",
635                         i, (unsigned)IPIQ[i].head, (unsigned)IPIQ[i].tail,
636                         IPIQ[i].depth);
637         }
638 }
639
640 /*
641  * The standard atomic.h primitives don't quite do what we want
642  * here: We need an atomic add-and-return-previous-value (which
643  * could be done with atomic_add_return and a decrement) and an
644  * atomic set/zero-and-return-previous-value (which can't really
645  * be done with the atomic.h primitives). And since this is
646  * MIPS MT, we can assume that we have LL/SC.
647  */
648 static __inline__ int atomic_postincrement(unsigned int *pv)
649 {
650         unsigned long result;
651
652         unsigned long temp;
653
654         __asm__ __volatile__(
655         "1:     ll      %0, %2                                  \n"
656         "       addu    %1, %0, 1                               \n"
657         "       sc      %1, %2                                  \n"
658         "       beqz    %1, 1b                                  \n"
659         "       sync                                            \n"
660         : "=&r" (result), "=&r" (temp), "=m" (*pv)
661         : "m" (*pv)
662         : "memory");
663
664         return result;
665 }
666
667 void smtc_send_ipi(int cpu, int type, unsigned int action)
668 {
669         int tcstatus;
670         struct smtc_ipi *pipi;
671         long flags;
672         int mtflags;
673
674         if (cpu == smp_processor_id()) {
675                 printk("Cannot Send IPI to self!\n");
676                 return;
677         }
678         /* Set up a descriptor, to be delivered either promptly or queued */
679         pipi = smtc_ipi_dq(&freeIPIq);
680         if (pipi == NULL) {
681                 bust_spinlocks(1);
682                 mips_mt_regdump(dvpe());
683                 panic("IPI Msg. Buffers Depleted\n");
684         }
685         pipi->type = type;
686         pipi->arg = (void *)action;
687         pipi->dest = cpu;
688         if (cpu_data[cpu].vpe_id != cpu_data[smp_processor_id()].vpe_id) {
689                 /* If not on same VPE, enqueue and send cross-VPE interupt */
690                 smtc_ipi_nq(&IPIQ[cpu], pipi);
691                 LOCK_CORE_PRA();
692                 settc(cpu_data[cpu].tc_id);
693                 write_vpe_c0_cause(read_vpe_c0_cause() | C_SW1);
694                 UNLOCK_CORE_PRA();
695         } else {
696                 /*
697                  * Not sufficient to do a LOCK_MT_PRA (dmt) here,
698                  * since ASID shootdown on the other VPE may
699                  * collide with this operation.
700                  */
701                 LOCK_CORE_PRA();
702                 settc(cpu_data[cpu].tc_id);
703                 /* Halt the targeted TC */
704                 write_tc_c0_tchalt(TCHALT_H);
705                 mips_ihb();
706
707                 /*
708                  * Inspect TCStatus - if IXMT is set, we have to queue
709                  * a message. Otherwise, we set up the "interrupt"
710                  * of the other TC
711                  */
712                 tcstatus = read_tc_c0_tcstatus();
713
714                 if ((tcstatus & TCSTATUS_IXMT) != 0) {
715                         /*
716                          * Spin-waiting here can deadlock,
717                          * so we queue the message for the target TC.
718                          */
719                         write_tc_c0_tchalt(0);
720                         UNLOCK_CORE_PRA();
721                         /* Try to reduce redundant timer interrupt messages */
722                         if (type == SMTC_CLOCK_TICK) {
723                             if (atomic_postincrement(&ipi_timer_latch[cpu])!=0){
724                                 smtc_ipi_nq(&freeIPIq, pipi);
725                                 return;
726                             }
727                         }
728                         smtc_ipi_nq(&IPIQ[cpu], pipi);
729                 } else {
730                         post_direct_ipi(cpu, pipi);
731                         write_tc_c0_tchalt(0);
732                         UNLOCK_CORE_PRA();
733                 }
734         }
735 }
736
737 /*
738  * Send IPI message to Halted TC, TargTC/TargVPE already having been set
739  */
740 static void post_direct_ipi(int cpu, struct smtc_ipi *pipi)
741 {
742         struct pt_regs *kstack;
743         unsigned long tcstatus;
744         unsigned long tcrestart;
745         extern u32 kernelsp[NR_CPUS];
746         extern void __smtc_ipi_vector(void);
747
748         /* Extract Status, EPC from halted TC */
749         tcstatus = read_tc_c0_tcstatus();
750         tcrestart = read_tc_c0_tcrestart();
751         /* If TCRestart indicates a WAIT instruction, advance the PC */
752         if ((tcrestart & 0x80000000)
753             && ((*(unsigned int *)tcrestart & 0xfe00003f) == 0x42000020)) {
754                 tcrestart += 4;
755         }
756         /*
757          * Save on TC's future kernel stack
758          *
759          * CU bit of Status is indicator that TC was
760          * already running on a kernel stack...
761          */
762         if (tcstatus & ST0_CU0)  {
763                 /* Note that this "- 1" is pointer arithmetic */
764                 kstack = ((struct pt_regs *)read_tc_gpr_sp()) - 1;
765         } else {
766                 kstack = ((struct pt_regs *)kernelsp[cpu]) - 1;
767         }
768
769         kstack->cp0_epc = (long)tcrestart;
770         /* Save TCStatus */
771         kstack->cp0_tcstatus = tcstatus;
772         /* Pass token of operation to be performed kernel stack pad area */
773         kstack->pad0[4] = (unsigned long)pipi;
774         /* Pass address of function to be called likewise */
775         kstack->pad0[5] = (unsigned long)&ipi_decode;
776         /* Set interrupt exempt and kernel mode */
777         tcstatus |= TCSTATUS_IXMT;
778         tcstatus &= ~TCSTATUS_TKSU;
779         write_tc_c0_tcstatus(tcstatus);
780         ehb();
781         /* Set TC Restart address to be SMTC IPI vector */
782         write_tc_c0_tcrestart(__smtc_ipi_vector);
783 }
784
785 static void ipi_resched_interrupt(void)
786 {
787         /* Return from interrupt should be enough to cause scheduler check */
788 }
789
790
791 static void ipi_call_interrupt(void)
792 {
793         /* Invoke generic function invocation code in smp.c */
794         smp_call_function_interrupt();
795 }
796
797 void ipi_decode(struct smtc_ipi *pipi)
798 {
799         void *arg_copy = pipi->arg;
800         int type_copy = pipi->type;
801         int dest_copy = pipi->dest;
802
803         smtc_ipi_nq(&freeIPIq, pipi);
804         switch (type_copy) {
805         case SMTC_CLOCK_TICK:
806                 irq_enter();
807                 kstat_this_cpu.irqs[MIPS_CPU_IRQ_BASE + cp0_compare_irq]++;
808                 /* Invoke Clock "Interrupt" */
809                 ipi_timer_latch[dest_copy] = 0;
810 #ifdef CONFIG_SMTC_IDLE_HOOK_DEBUG
811                 clock_hang_reported[dest_copy] = 0;
812 #endif /* CONFIG_SMTC_IDLE_HOOK_DEBUG */
813                 local_timer_interrupt(0, NULL);
814                 irq_exit();
815                 break;
816         case LINUX_SMP_IPI:
817                 switch ((int)arg_copy) {
818                 case SMP_RESCHEDULE_YOURSELF:
819                         ipi_resched_interrupt();
820                         break;
821                 case SMP_CALL_FUNCTION:
822                         ipi_call_interrupt();
823                         break;
824                 default:
825                         printk("Impossible SMTC IPI Argument 0x%x\n",
826                                 (int)arg_copy);
827                         break;
828                 }
829                 break;
830         default:
831                 printk("Impossible SMTC IPI Type 0x%x\n", type_copy);
832                 break;
833         }
834 }
835
836 void deferred_smtc_ipi(void)
837 {
838         struct smtc_ipi *pipi;
839         unsigned long flags;
840 /* DEBUG */
841         int q = smp_processor_id();
842
843         /*
844          * Test is not atomic, but much faster than a dequeue,
845          * and the vast majority of invocations will have a null queue.
846          */
847         if (IPIQ[q].head != NULL) {
848                 while((pipi = smtc_ipi_dq(&IPIQ[q])) != NULL) {
849                         /* ipi_decode() should be called with interrupts off */
850                         local_irq_save(flags);
851                         ipi_decode(pipi);
852                         local_irq_restore(flags);
853                 }
854         }
855 }
856
857 /*
858  * Send clock tick to all TCs except the one executing the funtion
859  */
860
861 void smtc_timer_broadcast(void)
862 {
863         int cpu;
864         int myTC = cpu_data[smp_processor_id()].tc_id;
865         int myVPE = cpu_data[smp_processor_id()].vpe_id;
866
867         smtc_cpu_stats[smp_processor_id()].timerints++;
868
869         for_each_online_cpu(cpu) {
870                 if (cpu_data[cpu].vpe_id == myVPE &&
871                     cpu_data[cpu].tc_id != myTC)
872                         smtc_send_ipi(cpu, SMTC_CLOCK_TICK, 0);
873         }
874 }
875
876 /*
877  * Cross-VPE interrupts in the SMTC prototype use "software interrupts"
878  * set via cross-VPE MTTR manipulation of the Cause register. It would be
879  * in some regards preferable to have external logic for "doorbell" hardware
880  * interrupts.
881  */
882
883 static int cpu_ipi_irq = MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_IRQ;
884
885 static irqreturn_t ipi_interrupt(int irq, void *dev_idm)
886 {
887         int my_vpe = cpu_data[smp_processor_id()].vpe_id;
888         int my_tc = cpu_data[smp_processor_id()].tc_id;
889         int cpu;
890         struct smtc_ipi *pipi;
891         unsigned long tcstatus;
892         int sent;
893         long flags;
894         unsigned int mtflags;
895         unsigned int vpflags;
896
897         /*
898          * So long as cross-VPE interrupts are done via
899          * MFTR/MTTR read-modify-writes of Cause, we need
900          * to stop other VPEs whenever the local VPE does
901          * anything similar.
902          */
903         local_irq_save(flags);
904         vpflags = dvpe();
905         clear_c0_cause(0x100 << MIPS_CPU_IPI_IRQ);
906         set_c0_status(0x100 << MIPS_CPU_IPI_IRQ);
907         irq_enable_hazard();
908         evpe(vpflags);
909         local_irq_restore(flags);
910
911         /*
912          * Cross-VPE Interrupt handler: Try to directly deliver IPIs
913          * queued for TCs on this VPE other than the current one.
914          * Return-from-interrupt should cause us to drain the queue
915          * for the current TC, so we ought not to have to do it explicitly here.
916          */
917
918         for_each_online_cpu(cpu) {
919                 if (cpu_data[cpu].vpe_id != my_vpe)
920                         continue;
921
922                 pipi = smtc_ipi_dq(&IPIQ[cpu]);
923                 if (pipi != NULL) {
924                         if (cpu_data[cpu].tc_id != my_tc) {
925                                 sent = 0;
926                                 LOCK_MT_PRA();
927                                 settc(cpu_data[cpu].tc_id);
928                                 write_tc_c0_tchalt(TCHALT_H);
929                                 mips_ihb();
930                                 tcstatus = read_tc_c0_tcstatus();
931                                 if ((tcstatus & TCSTATUS_IXMT) == 0) {
932                                         post_direct_ipi(cpu, pipi);
933                                         sent = 1;
934                                 }
935                                 write_tc_c0_tchalt(0);
936                                 UNLOCK_MT_PRA();
937                                 if (!sent) {
938                                         smtc_ipi_req(&IPIQ[cpu], pipi);
939                                 }
940                         } else {
941                                 /*
942                                  * ipi_decode() should be called
943                                  * with interrupts off
944                                  */
945                                 local_irq_save(flags);
946                                 ipi_decode(pipi);
947                                 local_irq_restore(flags);
948                         }
949                 }
950         }
951
952         return IRQ_HANDLED;
953 }
954
955 static void ipi_irq_dispatch(void)
956 {
957         do_IRQ(cpu_ipi_irq);
958 }
959
960 static struct irqaction irq_ipi = {
961         .handler        = ipi_interrupt,
962         .flags          = IRQF_DISABLED,
963         .name           = "SMTC_IPI",
964         .flags          = IRQF_PERCPU
965 };
966
967 static void setup_cross_vpe_interrupts(unsigned int nvpe)
968 {
969         if (nvpe < 1)
970                 return;
971
972         if (!cpu_has_vint)
973                 panic("SMTC Kernel requires Vectored Interupt support");
974
975         set_vi_handler(MIPS_CPU_IPI_IRQ, ipi_irq_dispatch);
976
977         setup_irq_smtc(cpu_ipi_irq, &irq_ipi, (0x100 << MIPS_CPU_IPI_IRQ));
978
979         set_irq_handler(cpu_ipi_irq, handle_percpu_irq);
980 }
981
982 /*
983  * SMTC-specific hacks invoked from elsewhere in the kernel.
984  *
985  * smtc_ipi_replay is called from raw_local_irq_restore which is only ever
986  * called with interrupts disabled.  We do rely on interrupts being disabled
987  * here because using spin_lock_irqsave()/spin_unlock_irqrestore() would
988  * result in a recursive call to raw_local_irq_restore().
989  */
990
991 static void __smtc_ipi_replay(void)
992 {
993         unsigned int cpu = smp_processor_id();
994
995         /*
996          * To the extent that we've ever turned interrupts off,
997          * we may have accumulated deferred IPIs.  This is subtle.
998          * If we use the smtc_ipi_qdepth() macro, we'll get an
999          * exact number - but we'll also disable interrupts
1000          * and create a window of failure where a new IPI gets
1001          * queued after we test the depth but before we re-enable
1002          * interrupts. So long as IXMT never gets set, however,
1003          * we should be OK:  If we pick up something and dispatch
1004          * it here, that's great. If we see nothing, but concurrent
1005          * with this operation, another TC sends us an IPI, IXMT
1006          * is clear, and we'll handle it as a real pseudo-interrupt
1007          * and not a pseudo-pseudo interrupt.
1008          */
1009         if (IPIQ[cpu].depth > 0) {
1010                 while (1) {
1011                         struct smtc_ipi_q *q = &IPIQ[cpu];
1012                         struct smtc_ipi *pipi;
1013                         extern void self_ipi(struct smtc_ipi *);
1014
1015                         spin_lock(&q->lock);
1016                         pipi = __smtc_ipi_dq(q);
1017                         spin_unlock(&q->lock);
1018                         if (!pipi)
1019                                 break;
1020
1021                         self_ipi(pipi);
1022                         smtc_cpu_stats[cpu].selfipis++;
1023                 }
1024         }
1025 }
1026
1027 void smtc_ipi_replay(void)
1028 {
1029         raw_local_irq_disable();
1030         __smtc_ipi_replay();
1031 }
1032
1033 EXPORT_SYMBOL(smtc_ipi_replay);
1034
1035 void smtc_idle_loop_hook(void)
1036 {
1037 #ifdef CONFIG_SMTC_IDLE_HOOK_DEBUG
1038         int im;
1039         int flags;
1040         int mtflags;
1041         int bit;
1042         int vpe;
1043         int tc;
1044         int hook_ntcs;
1045         /*
1046          * printk within DMT-protected regions can deadlock,
1047          * so buffer diagnostic messages for later output.
1048          */
1049         char *pdb_msg;
1050         char id_ho_db_msg[768]; /* worst-case use should be less than 700 */
1051
1052         if (atomic_read(&idle_hook_initialized) == 0) { /* fast test */
1053                 if (atomic_add_return(1, &idle_hook_initialized) == 1) {
1054                         int mvpconf0;
1055                         /* Tedious stuff to just do once */
1056                         mvpconf0 = read_c0_mvpconf0();
1057                         hook_ntcs = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
1058                         if (hook_ntcs > NR_CPUS)
1059                                 hook_ntcs = NR_CPUS;
1060                         for (tc = 0; tc < hook_ntcs; tc++) {
1061                                 tcnoprog[tc] = 0;
1062                                 clock_hang_reported[tc] = 0;
1063                         }
1064                         for (vpe = 0; vpe < 2; vpe++)
1065                                 for (im = 0; im < 8; im++)
1066                                         imstuckcount[vpe][im] = 0;
1067                         printk("Idle loop test hook initialized for %d TCs\n", hook_ntcs);
1068                         atomic_set(&idle_hook_initialized, 1000);
1069                 } else {
1070                         /* Someone else is initializing in parallel - let 'em finish */
1071                         while (atomic_read(&idle_hook_initialized) < 1000)
1072                                 ;
1073                 }
1074         }
1075
1076         /* Have we stupidly left IXMT set somewhere? */
1077         if (read_c0_tcstatus() & 0x400) {
1078                 write_c0_tcstatus(read_c0_tcstatus() & ~0x400);
1079                 ehb();
1080                 printk("Dangling IXMT in cpu_idle()\n");
1081         }
1082
1083         /* Have we stupidly left an IM bit turned off? */
1084 #define IM_LIMIT 2000
1085         local_irq_save(flags);
1086         mtflags = dmt();
1087         pdb_msg = &id_ho_db_msg[0];
1088         im = read_c0_status();
1089         vpe = current_cpu_data.vpe_id;
1090         for (bit = 0; bit < 8; bit++) {
1091                 /*
1092                  * In current prototype, I/O interrupts
1093                  * are masked for VPE > 0
1094                  */
1095                 if (vpemask[vpe][bit]) {
1096                         if (!(im & (0x100 << bit)))
1097                                 imstuckcount[vpe][bit]++;
1098                         else
1099                                 imstuckcount[vpe][bit] = 0;
1100                         if (imstuckcount[vpe][bit] > IM_LIMIT) {
1101                                 set_c0_status(0x100 << bit);
1102                                 ehb();
1103                                 imstuckcount[vpe][bit] = 0;
1104                                 pdb_msg += sprintf(pdb_msg,
1105                                         "Dangling IM %d fixed for VPE %d\n", bit,
1106                                         vpe);
1107                         }
1108                 }
1109         }
1110
1111         /*
1112          * Now that we limit outstanding timer IPIs, check for hung TC
1113          */
1114         for (tc = 0; tc < NR_CPUS; tc++) {
1115                 /* Don't check ourself - we'll dequeue IPIs just below */
1116                 if ((tc != smp_processor_id()) &&
1117                     ipi_timer_latch[tc] > timerq_limit) {
1118                     if (clock_hang_reported[tc] == 0) {
1119                         pdb_msg += sprintf(pdb_msg,
1120                                 "TC %d looks hung with timer latch at %d\n",
1121                                 tc, ipi_timer_latch[tc]);
1122                         clock_hang_reported[tc]++;
1123                         }
1124                 }
1125         }
1126         emt(mtflags);
1127         local_irq_restore(flags);
1128         if (pdb_msg != &id_ho_db_msg[0])
1129                 printk("CPU%d: %s", smp_processor_id(), id_ho_db_msg);
1130 #endif /* CONFIG_SMTC_IDLE_HOOK_DEBUG */
1131
1132         /*
1133          * Replay any accumulated deferred IPIs. If "Instant Replay"
1134          * is in use, there should never be any.
1135          */
1136 #ifndef CONFIG_MIPS_MT_SMTC_INSTANT_REPLAY
1137         {
1138                 unsigned long flags;
1139
1140                 local_irq_save(flags);
1141                 __smtc_ipi_replay();
1142                 local_irq_restore(flags);
1143         }
1144 #endif /* CONFIG_MIPS_MT_SMTC_INSTANT_REPLAY */
1145 }
1146
1147 void smtc_soft_dump(void)
1148 {
1149         int i;
1150
1151         printk("Counter Interrupts taken per CPU (TC)\n");
1152         for (i=0; i < NR_CPUS; i++) {
1153                 printk("%d: %ld\n", i, smtc_cpu_stats[i].timerints);
1154         }
1155         printk("Self-IPI invocations:\n");
1156         for (i=0; i < NR_CPUS; i++) {
1157                 printk("%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
1158         }
1159         smtc_ipi_qdump();
1160         printk("Timer IPI Backlogs:\n");
1161         for (i=0; i < NR_CPUS; i++) {
1162                 printk("%d: %d\n", i, ipi_timer_latch[i]);
1163         }
1164         printk("%d Recoveries of \"stolen\" FPU\n",
1165                atomic_read(&smtc_fpu_recoveries));
1166 }
1167
1168
1169 /*
1170  * TLB management routines special to SMTC
1171  */
1172
1173 void smtc_get_new_mmu_context(struct mm_struct *mm, unsigned long cpu)
1174 {
1175         unsigned long flags, mtflags, tcstat, prevhalt, asid;
1176         int tlb, i;
1177
1178         /*
1179          * It would be nice to be able to use a spinlock here,
1180          * but this is invoked from within TLB flush routines
1181          * that protect themselves with DVPE, so if a lock is
1182          * held by another TC, it'll never be freed.
1183          *
1184          * DVPE/DMT must not be done with interrupts enabled,
1185          * so even so most callers will already have disabled
1186          * them, let's be really careful...
1187          */
1188
1189         local_irq_save(flags);
1190         if (smtc_status & SMTC_TLB_SHARED) {
1191                 mtflags = dvpe();
1192                 tlb = 0;
1193         } else {
1194                 mtflags = dmt();
1195                 tlb = cpu_data[cpu].vpe_id;
1196         }
1197         asid = asid_cache(cpu);
1198
1199         do {
1200                 if (!((asid += ASID_INC) & ASID_MASK) ) {
1201                         if (cpu_has_vtag_icache)
1202                                 flush_icache_all();
1203                         /* Traverse all online CPUs (hack requires contigous range) */
1204                         for (i = 0; i < num_online_cpus(); i++) {
1205                                 /*
1206                                  * We don't need to worry about our own CPU, nor those of
1207                                  * CPUs who don't share our TLB.
1208                                  */
1209                                 if ((i != smp_processor_id()) &&
1210                                     ((smtc_status & SMTC_TLB_SHARED) ||
1211                                      (cpu_data[i].vpe_id == cpu_data[cpu].vpe_id))) {
1212                                         settc(cpu_data[i].tc_id);
1213                                         prevhalt = read_tc_c0_tchalt() & TCHALT_H;
1214                                         if (!prevhalt) {
1215                                                 write_tc_c0_tchalt(TCHALT_H);
1216                                                 mips_ihb();
1217                                         }
1218                                         tcstat = read_tc_c0_tcstatus();
1219                                         smtc_live_asid[tlb][(tcstat & ASID_MASK)] |= (asiduse)(0x1 << i);
1220                                         if (!prevhalt)
1221                                                 write_tc_c0_tchalt(0);
1222                                 }
1223                         }
1224                         if (!asid)              /* fix version if needed */
1225                                 asid = ASID_FIRST_VERSION;
1226                         local_flush_tlb_all();  /* start new asid cycle */
1227                 }
1228         } while (smtc_live_asid[tlb][(asid & ASID_MASK)]);
1229
1230         /*
1231          * SMTC shares the TLB within VPEs and possibly across all VPEs.
1232          */
1233         for (i = 0; i < num_online_cpus(); i++) {
1234                 if ((smtc_status & SMTC_TLB_SHARED) ||
1235                     (cpu_data[i].vpe_id == cpu_data[cpu].vpe_id))
1236                         cpu_context(i, mm) = asid_cache(i) = asid;
1237         }
1238
1239         if (smtc_status & SMTC_TLB_SHARED)
1240                 evpe(mtflags);
1241         else
1242                 emt(mtflags);
1243         local_irq_restore(flags);
1244 }
1245
1246 /*
1247  * Invoked from macros defined in mmu_context.h
1248  * which must already have disabled interrupts
1249  * and done a DVPE or DMT as appropriate.
1250  */
1251
1252 void smtc_flush_tlb_asid(unsigned long asid)
1253 {
1254         int entry;
1255         unsigned long ehi;
1256
1257         entry = read_c0_wired();
1258
1259         /* Traverse all non-wired entries */
1260         while (entry < current_cpu_data.tlbsize) {
1261                 write_c0_index(entry);
1262                 ehb();
1263                 tlb_read();
1264                 ehb();
1265                 ehi = read_c0_entryhi();
1266                 if ((ehi & ASID_MASK) == asid) {
1267                     /*
1268                      * Invalidate only entries with specified ASID,
1269                      * makiing sure all entries differ.
1270                      */
1271                     write_c0_entryhi(CKSEG0 + (entry << (PAGE_SHIFT + 1)));
1272                     write_c0_entrylo0(0);
1273                     write_c0_entrylo1(0);
1274                     mtc0_tlbw_hazard();
1275                     tlb_write_indexed();
1276                 }
1277                 entry++;
1278         }
1279         write_c0_index(PARKED_INDEX);
1280         tlbw_use_hazard();
1281 }
1282
1283 /*
1284  * Support for single-threading cache flush operations.
1285  */
1286
1287 static int halt_state_save[NR_CPUS];
1288
1289 /*
1290  * To really, really be sure that nothing is being done
1291  * by other TCs, halt them all.  This code assumes that
1292  * a DVPE has already been done, so while their Halted
1293  * state is theoretically architecturally unstable, in
1294  * practice, it's not going to change while we're looking
1295  * at it.
1296  */
1297
1298 void smtc_cflush_lockdown(void)
1299 {
1300         int cpu;
1301
1302         for_each_online_cpu(cpu) {
1303                 if (cpu != smp_processor_id()) {
1304                         settc(cpu_data[cpu].tc_id);
1305                         halt_state_save[cpu] = read_tc_c0_tchalt();
1306                         write_tc_c0_tchalt(TCHALT_H);
1307                 }
1308         }
1309         mips_ihb();
1310 }
1311
1312 /* It would be cheating to change the cpu_online states during a flush! */
1313
1314 void smtc_cflush_release(void)
1315 {
1316         int cpu;
1317
1318         /*
1319          * Start with a hazard barrier to ensure
1320          * that all CACHE ops have played through.
1321          */
1322         mips_ihb();
1323
1324         for_each_online_cpu(cpu) {
1325                 if (cpu != smp_processor_id()) {
1326                         settc(cpu_data[cpu].tc_id);
1327                         write_tc_c0_tchalt(halt_state_save[cpu]);
1328                 }
1329         }
1330         mips_ihb();
1331 }