smtc.c 33 KB

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