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