smtc.c 33 KB

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