smtc.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  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/mmu_context.h>
  15. #include <asm/smp.h>
  16. #include <asm/mips-boards/maltaint.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 vpelimit = 0;
  66. static int tclimit = 0;
  67. static int ipibuffers = 0;
  68. static int nostlb = 0;
  69. static int asidmask = 0;
  70. unsigned long smtc_asid_mask = 0xff;
  71. static int __init maxvpes(char *str)
  72. {
  73. get_option(&str, &vpelimit);
  74. return 1;
  75. }
  76. static int __init maxtcs(char *str)
  77. {
  78. get_option(&str, &tclimit);
  79. return 1;
  80. }
  81. static int __init ipibufs(char *str)
  82. {
  83. get_option(&str, &ipibuffers);
  84. return 1;
  85. }
  86. static int __init stlb_disable(char *s)
  87. {
  88. nostlb = 1;
  89. return 1;
  90. }
  91. static int __init asidmask_set(char *str)
  92. {
  93. get_option(&str, &asidmask);
  94. switch (asidmask) {
  95. case 0x1:
  96. case 0x3:
  97. case 0x7:
  98. case 0xf:
  99. case 0x1f:
  100. case 0x3f:
  101. case 0x7f:
  102. case 0xff:
  103. smtc_asid_mask = (unsigned long)asidmask;
  104. break;
  105. default:
  106. printk("ILLEGAL ASID mask 0x%x from command line\n", asidmask);
  107. }
  108. return 1;
  109. }
  110. __setup("maxvpes=", maxvpes);
  111. __setup("maxtcs=", maxtcs);
  112. __setup("ipibufs=", ipibufs);
  113. __setup("nostlb", stlb_disable);
  114. __setup("asidmask=", asidmask_set);
  115. #ifdef CONFIG_SMTC_IDLE_HOOK_DEBUG
  116. static int hang_trig = 0;
  117. static int __init hangtrig_enable(char *s)
  118. {
  119. hang_trig = 1;
  120. return 1;
  121. }
  122. __setup("hangtrig", hangtrig_enable);
  123. #define DEFAULT_BLOCKED_IPI_LIMIT 32
  124. static int timerq_limit = DEFAULT_BLOCKED_IPI_LIMIT;
  125. static int __init tintq(char *str)
  126. {
  127. get_option(&str, &timerq_limit);
  128. return 1;
  129. }
  130. __setup("tintq=", tintq);
  131. int imstuckcount[2][8];
  132. /* vpemask represents IM/IE bits of per-VPE Status registers, low-to-high */
  133. int vpemask[2][8] = {
  134. {0, 0, 1, 0, 0, 0, 0, 1},
  135. {0, 0, 0, 0, 0, 0, 0, 1}
  136. };
  137. int tcnoprog[NR_CPUS];
  138. static atomic_t idle_hook_initialized = {0};
  139. static int clock_hang_reported[NR_CPUS];
  140. #endif /* CONFIG_SMTC_IDLE_HOOK_DEBUG */
  141. /* Initialize shared TLB - the should probably migrate to smtc_setup_cpus() */
  142. void __init sanitize_tlb_entries(void)
  143. {
  144. printk("Deprecated sanitize_tlb_entries() invoked\n");
  145. }
  146. /*
  147. * Configure shared TLB - VPC configuration bit must be set by caller
  148. */
  149. static void smtc_configure_tlb(void)
  150. {
  151. int i,tlbsiz,vpes;
  152. unsigned long mvpconf0;
  153. unsigned long config1val;
  154. /* Set up ASID preservation table */
  155. for (vpes=0; vpes<MAX_SMTC_TLBS; vpes++) {
  156. for(i = 0; i < MAX_SMTC_ASIDS; i++) {
  157. smtc_live_asid[vpes][i] = 0;
  158. }
  159. }
  160. mvpconf0 = read_c0_mvpconf0();
  161. if ((vpes = ((mvpconf0 & MVPCONF0_PVPE)
  162. >> MVPCONF0_PVPE_SHIFT) + 1) > 1) {
  163. /* If we have multiple VPEs, try to share the TLB */
  164. if ((mvpconf0 & MVPCONF0_TLBS) && !nostlb) {
  165. /*
  166. * If TLB sizing is programmable, shared TLB
  167. * size is the total available complement.
  168. * Otherwise, we have to take the sum of all
  169. * static VPE TLB entries.
  170. */
  171. if ((tlbsiz = ((mvpconf0 & MVPCONF0_PTLBE)
  172. >> MVPCONF0_PTLBE_SHIFT)) == 0) {
  173. /*
  174. * If there's more than one VPE, there had better
  175. * be more than one TC, because we need one to bind
  176. * to each VPE in turn to be able to read
  177. * its configuration state!
  178. */
  179. settc(1);
  180. /* Stop the TC from doing anything foolish */
  181. write_tc_c0_tchalt(TCHALT_H);
  182. mips_ihb();
  183. /* No need to un-Halt - that happens later anyway */
  184. for (i=0; i < vpes; i++) {
  185. write_tc_c0_tcbind(i);
  186. /*
  187. * To be 100% sure we're really getting the right
  188. * information, we exit the configuration state
  189. * and do an IHB after each rebinding.
  190. */
  191. write_c0_mvpcontrol(
  192. read_c0_mvpcontrol() & ~ MVPCONTROL_VPC );
  193. mips_ihb();
  194. /*
  195. * Only count if the MMU Type indicated is TLB
  196. */
  197. if (((read_vpe_c0_config() & MIPS_CONF_MT) >> 7) == 1) {
  198. config1val = read_vpe_c0_config1();
  199. tlbsiz += ((config1val >> 25) & 0x3f) + 1;
  200. }
  201. /* Put core back in configuration state */
  202. write_c0_mvpcontrol(
  203. read_c0_mvpcontrol() | MVPCONTROL_VPC );
  204. mips_ihb();
  205. }
  206. }
  207. write_c0_mvpcontrol(read_c0_mvpcontrol() | MVPCONTROL_STLB);
  208. ehb();
  209. /*
  210. * Setup kernel data structures to use software total,
  211. * rather than read the per-VPE Config1 value. The values
  212. * for "CPU 0" gets copied to all the other CPUs as part
  213. * of their initialization in smtc_cpu_setup().
  214. */
  215. /* MIPS32 limits TLB indices to 64 */
  216. if (tlbsiz > 64)
  217. tlbsiz = 64;
  218. cpu_data[0].tlbsize = current_cpu_data.tlbsize = tlbsiz;
  219. smtc_status |= SMTC_TLB_SHARED;
  220. local_flush_tlb_all();
  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 CONFIG_SMTC_IDLE_HOOK_DEBUG
  332. if (hang_trig)
  333. printk("Logic Analyser Trigger on suspected TC hang\n");
  334. #endif /* CONFIG_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. setup_cross_vpe_interrupts(nvpe);
  429. /* Set up queue of free IPI "messages". */
  430. nipi = NR_CPUS * IPIBUF_PER_CPU;
  431. if (ipibuffers > 0)
  432. nipi = ipibuffers;
  433. pipi = kmalloc(nipi *sizeof(struct smtc_ipi), GFP_KERNEL);
  434. if (pipi == NULL)
  435. panic("kmalloc of IPI message buffers failed\n");
  436. else
  437. printk("IPI buffer pool of %d buffers\n", nipi);
  438. for (i = 0; i < nipi; i++) {
  439. smtc_ipi_nq(&freeIPIq, pipi);
  440. pipi++;
  441. }
  442. /* Arm multithreading and enable other VPEs - but all TCs are Halted */
  443. emt(EMT_ENABLE);
  444. evpe(EVPE_ENABLE);
  445. local_irq_restore(flags);
  446. /* Initialize SMTC /proc statistics/diagnostics */
  447. init_smtc_stats();
  448. }
  449. /*
  450. * Setup the PC, SP, and GP of a secondary processor and start it
  451. * running!
  452. * smp_bootstrap is the place to resume from
  453. * __KSTK_TOS(idle) is apparently the stack pointer
  454. * (unsigned long)idle->thread_info the gp
  455. *
  456. */
  457. void smtc_boot_secondary(int cpu, struct task_struct *idle)
  458. {
  459. extern u32 kernelsp[NR_CPUS];
  460. long flags;
  461. int mtflags;
  462. LOCK_MT_PRA();
  463. if (cpu_data[cpu].vpe_id != cpu_data[smp_processor_id()].vpe_id) {
  464. dvpe();
  465. }
  466. settc(cpu_data[cpu].tc_id);
  467. /* pc */
  468. write_tc_c0_tcrestart((unsigned long)&smp_bootstrap);
  469. /* stack pointer */
  470. kernelsp[cpu] = __KSTK_TOS(idle);
  471. write_tc_gpr_sp(__KSTK_TOS(idle));
  472. /* global pointer */
  473. write_tc_gpr_gp((unsigned long)idle->thread_info);
  474. smtc_status |= SMTC_MTC_ACTIVE;
  475. write_tc_c0_tchalt(0);
  476. if (cpu_data[cpu].vpe_id != cpu_data[smp_processor_id()].vpe_id) {
  477. evpe(EVPE_ENABLE);
  478. }
  479. UNLOCK_MT_PRA();
  480. }
  481. void smtc_init_secondary(void)
  482. {
  483. /*
  484. * Start timer on secondary VPEs if necessary.
  485. * plat_timer_setup has already have been invoked by init/main
  486. * on "boot" TC. Like per_cpu_trap_init() hack, this assumes that
  487. * SMTC init code assigns TCs consdecutively and in ascending order
  488. * to across available VPEs.
  489. */
  490. if (((read_c0_tcbind() & TCBIND_CURTC) != 0) &&
  491. ((read_c0_tcbind() & TCBIND_CURVPE)
  492. != cpu_data[smp_processor_id() - 1].vpe_id)){
  493. write_c0_compare (read_c0_count() + mips_hpt_frequency/HZ);
  494. }
  495. local_irq_enable();
  496. }
  497. void smtc_smp_finish(void)
  498. {
  499. printk("TC %d going on-line as CPU %d\n",
  500. cpu_data[smp_processor_id()].tc_id, smp_processor_id());
  501. }
  502. void smtc_cpus_done(void)
  503. {
  504. }
  505. /*
  506. * Support for SMTC-optimized driver IRQ registration
  507. */
  508. /*
  509. * SMTC Kernel needs to manipulate low-level CPU interrupt mask
  510. * in do_IRQ. These are passed in setup_irq_smtc() and stored
  511. * in this table.
  512. */
  513. int setup_irq_smtc(unsigned int irq, struct irqaction * new,
  514. unsigned long hwmask)
  515. {
  516. unsigned int vpe = current_cpu_data.vpe_id;
  517. irq_hwmask[irq] = hwmask;
  518. #ifdef CONFIG_SMTC_IDLE_HOOK_DEBUG
  519. vpemask[vpe][irq - MIPSCPU_INT_BASE] = 1;
  520. #endif
  521. return setup_irq(irq, new);
  522. }
  523. /*
  524. * IPI model for SMTC is tricky, because interrupts aren't TC-specific.
  525. * Within a VPE one TC can interrupt another by different approaches.
  526. * The easiest to get right would probably be to make all TCs except
  527. * the target IXMT and set a software interrupt, but an IXMT-based
  528. * scheme requires that a handler must run before a new IPI could
  529. * be sent, which would break the "broadcast" loops in MIPS MT.
  530. * A more gonzo approach within a VPE is to halt the TC, extract
  531. * its Restart, Status, and a couple of GPRs, and program the Restart
  532. * address to emulate an interrupt.
  533. *
  534. * Within a VPE, one can be confident that the target TC isn't in
  535. * a critical EXL state when halted, since the write to the Halt
  536. * register could not have issued on the writing thread if the
  537. * halting thread had EXL set. So k0 and k1 of the target TC
  538. * can be used by the injection code. Across VPEs, one can't
  539. * be certain that the target TC isn't in a critical exception
  540. * state. So we try a two-step process of sending a software
  541. * interrupt to the target VPE, which either handles the event
  542. * itself (if it was the target) or injects the event within
  543. * the VPE.
  544. */
  545. static void smtc_ipi_qdump(void)
  546. {
  547. int i;
  548. for (i = 0; i < NR_CPUS ;i++) {
  549. printk("IPIQ[%d]: head = 0x%x, tail = 0x%x, depth = %d\n",
  550. i, (unsigned)IPIQ[i].head, (unsigned)IPIQ[i].tail,
  551. IPIQ[i].depth);
  552. }
  553. }
  554. /*
  555. * The standard atomic.h primitives don't quite do what we want
  556. * here: We need an atomic add-and-return-previous-value (which
  557. * could be done with atomic_add_return and a decrement) and an
  558. * atomic set/zero-and-return-previous-value (which can't really
  559. * be done with the atomic.h primitives). And since this is
  560. * MIPS MT, we can assume that we have LL/SC.
  561. */
  562. static __inline__ int atomic_postincrement(unsigned int *pv)
  563. {
  564. unsigned long result;
  565. unsigned long temp;
  566. __asm__ __volatile__(
  567. "1: ll %0, %2 \n"
  568. " addu %1, %0, 1 \n"
  569. " sc %1, %2 \n"
  570. " beqz %1, 1b \n"
  571. " sync \n"
  572. : "=&r" (result), "=&r" (temp), "=m" (*pv)
  573. : "m" (*pv)
  574. : "memory");
  575. return result;
  576. }
  577. void smtc_send_ipi(int cpu, int type, unsigned int action)
  578. {
  579. int tcstatus;
  580. struct smtc_ipi *pipi;
  581. long flags;
  582. int mtflags;
  583. if (cpu == smp_processor_id()) {
  584. printk("Cannot Send IPI to self!\n");
  585. return;
  586. }
  587. /* Set up a descriptor, to be delivered either promptly or queued */
  588. pipi = smtc_ipi_dq(&freeIPIq);
  589. if (pipi == NULL) {
  590. bust_spinlocks(1);
  591. mips_mt_regdump(dvpe());
  592. panic("IPI Msg. Buffers Depleted\n");
  593. }
  594. pipi->type = type;
  595. pipi->arg = (void *)action;
  596. pipi->dest = cpu;
  597. if (cpu_data[cpu].vpe_id != cpu_data[smp_processor_id()].vpe_id) {
  598. /* If not on same VPE, enqueue and send cross-VPE interupt */
  599. smtc_ipi_nq(&IPIQ[cpu], pipi);
  600. LOCK_CORE_PRA();
  601. settc(cpu_data[cpu].tc_id);
  602. write_vpe_c0_cause(read_vpe_c0_cause() | C_SW1);
  603. UNLOCK_CORE_PRA();
  604. } else {
  605. /*
  606. * Not sufficient to do a LOCK_MT_PRA (dmt) here,
  607. * since ASID shootdown on the other VPE may
  608. * collide with this operation.
  609. */
  610. LOCK_CORE_PRA();
  611. settc(cpu_data[cpu].tc_id);
  612. /* Halt the targeted TC */
  613. write_tc_c0_tchalt(TCHALT_H);
  614. mips_ihb();
  615. /*
  616. * Inspect TCStatus - if IXMT is set, we have to queue
  617. * a message. Otherwise, we set up the "interrupt"
  618. * of the other TC
  619. */
  620. tcstatus = read_tc_c0_tcstatus();
  621. if ((tcstatus & TCSTATUS_IXMT) != 0) {
  622. /*
  623. * Spin-waiting here can deadlock,
  624. * so we queue the message for the target TC.
  625. */
  626. write_tc_c0_tchalt(0);
  627. UNLOCK_CORE_PRA();
  628. /* Try to reduce redundant timer interrupt messages */
  629. if (type == SMTC_CLOCK_TICK) {
  630. if (atomic_postincrement(&ipi_timer_latch[cpu])!=0){
  631. smtc_ipi_nq(&freeIPIq, pipi);
  632. return;
  633. }
  634. }
  635. smtc_ipi_nq(&IPIQ[cpu], pipi);
  636. } else {
  637. post_direct_ipi(cpu, pipi);
  638. write_tc_c0_tchalt(0);
  639. UNLOCK_CORE_PRA();
  640. }
  641. }
  642. }
  643. /*
  644. * Send IPI message to Halted TC, TargTC/TargVPE already having been set
  645. */
  646. static void post_direct_ipi(int cpu, struct smtc_ipi *pipi)
  647. {
  648. struct pt_regs *kstack;
  649. unsigned long tcstatus;
  650. unsigned long tcrestart;
  651. extern u32 kernelsp[NR_CPUS];
  652. extern void __smtc_ipi_vector(void);
  653. /* Extract Status, EPC from halted TC */
  654. tcstatus = read_tc_c0_tcstatus();
  655. tcrestart = read_tc_c0_tcrestart();
  656. /* If TCRestart indicates a WAIT instruction, advance the PC */
  657. if ((tcrestart & 0x80000000)
  658. && ((*(unsigned int *)tcrestart & 0xfe00003f) == 0x42000020)) {
  659. tcrestart += 4;
  660. }
  661. /*
  662. * Save on TC's future kernel stack
  663. *
  664. * CU bit of Status is indicator that TC was
  665. * already running on a kernel stack...
  666. */
  667. if (tcstatus & ST0_CU0) {
  668. /* Note that this "- 1" is pointer arithmetic */
  669. kstack = ((struct pt_regs *)read_tc_gpr_sp()) - 1;
  670. } else {
  671. kstack = ((struct pt_regs *)kernelsp[cpu]) - 1;
  672. }
  673. kstack->cp0_epc = (long)tcrestart;
  674. /* Save TCStatus */
  675. kstack->cp0_tcstatus = tcstatus;
  676. /* Pass token of operation to be performed kernel stack pad area */
  677. kstack->pad0[4] = (unsigned long)pipi;
  678. /* Pass address of function to be called likewise */
  679. kstack->pad0[5] = (unsigned long)&ipi_decode;
  680. /* Set interrupt exempt and kernel mode */
  681. tcstatus |= TCSTATUS_IXMT;
  682. tcstatus &= ~TCSTATUS_TKSU;
  683. write_tc_c0_tcstatus(tcstatus);
  684. ehb();
  685. /* Set TC Restart address to be SMTC IPI vector */
  686. write_tc_c0_tcrestart(__smtc_ipi_vector);
  687. }
  688. static void ipi_resched_interrupt(void)
  689. {
  690. /* Return from interrupt should be enough to cause scheduler check */
  691. }
  692. static void ipi_call_interrupt(void)
  693. {
  694. /* Invoke generic function invocation code in smp.c */
  695. smp_call_function_interrupt();
  696. }
  697. void ipi_decode(struct smtc_ipi *pipi)
  698. {
  699. void *arg_copy = pipi->arg;
  700. int type_copy = pipi->type;
  701. int dest_copy = pipi->dest;
  702. smtc_ipi_nq(&freeIPIq, pipi);
  703. switch (type_copy) {
  704. case SMTC_CLOCK_TICK:
  705. irq_enter();
  706. kstat_this_cpu.irqs[MIPSCPU_INT_BASE + MIPSCPU_INT_CPUCTR]++;
  707. /* Invoke Clock "Interrupt" */
  708. ipi_timer_latch[dest_copy] = 0;
  709. #ifdef CONFIG_SMTC_IDLE_HOOK_DEBUG
  710. clock_hang_reported[dest_copy] = 0;
  711. #endif /* CONFIG_SMTC_IDLE_HOOK_DEBUG */
  712. local_timer_interrupt(0, NULL);
  713. irq_exit();
  714. break;
  715. case LINUX_SMP_IPI:
  716. switch ((int)arg_copy) {
  717. case SMP_RESCHEDULE_YOURSELF:
  718. ipi_resched_interrupt();
  719. break;
  720. case SMP_CALL_FUNCTION:
  721. ipi_call_interrupt();
  722. break;
  723. default:
  724. printk("Impossible SMTC IPI Argument 0x%x\n",
  725. (int)arg_copy);
  726. break;
  727. }
  728. break;
  729. default:
  730. printk("Impossible SMTC IPI Type 0x%x\n", type_copy);
  731. break;
  732. }
  733. }
  734. void deferred_smtc_ipi(void)
  735. {
  736. struct smtc_ipi *pipi;
  737. unsigned long flags;
  738. /* DEBUG */
  739. int q = smp_processor_id();
  740. /*
  741. * Test is not atomic, but much faster than a dequeue,
  742. * and the vast majority of invocations will have a null queue.
  743. */
  744. if (IPIQ[q].head != NULL) {
  745. while((pipi = smtc_ipi_dq(&IPIQ[q])) != NULL) {
  746. /* ipi_decode() should be called with interrupts off */
  747. local_irq_save(flags);
  748. ipi_decode(pipi);
  749. local_irq_restore(flags);
  750. }
  751. }
  752. }
  753. /*
  754. * Send clock tick to all TCs except the one executing the funtion
  755. */
  756. void smtc_timer_broadcast(int vpe)
  757. {
  758. int cpu;
  759. int myTC = cpu_data[smp_processor_id()].tc_id;
  760. int myVPE = cpu_data[smp_processor_id()].vpe_id;
  761. smtc_cpu_stats[smp_processor_id()].timerints++;
  762. for_each_online_cpu(cpu) {
  763. if (cpu_data[cpu].vpe_id == myVPE &&
  764. cpu_data[cpu].tc_id != myTC)
  765. smtc_send_ipi(cpu, SMTC_CLOCK_TICK, 0);
  766. }
  767. }
  768. /*
  769. * Cross-VPE interrupts in the SMTC prototype use "software interrupts"
  770. * set via cross-VPE MTTR manipulation of the Cause register. It would be
  771. * in some regards preferable to have external logic for "doorbell" hardware
  772. * interrupts.
  773. */
  774. static int cpu_ipi_irq = MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_IRQ;
  775. static irqreturn_t ipi_interrupt(int irq, void *dev_idm)
  776. {
  777. int my_vpe = cpu_data[smp_processor_id()].vpe_id;
  778. int my_tc = cpu_data[smp_processor_id()].tc_id;
  779. int cpu;
  780. struct smtc_ipi *pipi;
  781. unsigned long tcstatus;
  782. int sent;
  783. long flags;
  784. unsigned int mtflags;
  785. unsigned int vpflags;
  786. /*
  787. * So long as cross-VPE interrupts are done via
  788. * MFTR/MTTR read-modify-writes of Cause, we need
  789. * to stop other VPEs whenever the local VPE does
  790. * anything similar.
  791. */
  792. local_irq_save(flags);
  793. vpflags = dvpe();
  794. clear_c0_cause(0x100 << MIPS_CPU_IPI_IRQ);
  795. set_c0_status(0x100 << MIPS_CPU_IPI_IRQ);
  796. irq_enable_hazard();
  797. evpe(vpflags);
  798. local_irq_restore(flags);
  799. /*
  800. * Cross-VPE Interrupt handler: Try to directly deliver IPIs
  801. * queued for TCs on this VPE other than the current one.
  802. * Return-from-interrupt should cause us to drain the queue
  803. * for the current TC, so we ought not to have to do it explicitly here.
  804. */
  805. for_each_online_cpu(cpu) {
  806. if (cpu_data[cpu].vpe_id != my_vpe)
  807. continue;
  808. pipi = smtc_ipi_dq(&IPIQ[cpu]);
  809. if (pipi != NULL) {
  810. if (cpu_data[cpu].tc_id != my_tc) {
  811. sent = 0;
  812. LOCK_MT_PRA();
  813. settc(cpu_data[cpu].tc_id);
  814. write_tc_c0_tchalt(TCHALT_H);
  815. mips_ihb();
  816. tcstatus = read_tc_c0_tcstatus();
  817. if ((tcstatus & TCSTATUS_IXMT) == 0) {
  818. post_direct_ipi(cpu, pipi);
  819. sent = 1;
  820. }
  821. write_tc_c0_tchalt(0);
  822. UNLOCK_MT_PRA();
  823. if (!sent) {
  824. smtc_ipi_req(&IPIQ[cpu], pipi);
  825. }
  826. } else {
  827. /*
  828. * ipi_decode() should be called
  829. * with interrupts off
  830. */
  831. local_irq_save(flags);
  832. ipi_decode(pipi);
  833. local_irq_restore(flags);
  834. }
  835. }
  836. }
  837. return IRQ_HANDLED;
  838. }
  839. static void ipi_irq_dispatch(void)
  840. {
  841. do_IRQ(cpu_ipi_irq);
  842. }
  843. static struct irqaction irq_ipi;
  844. static void setup_cross_vpe_interrupts(unsigned int nvpe)
  845. {
  846. if (nvpe < 1)
  847. return;
  848. if (!cpu_has_vint)
  849. panic("SMTC Kernel requires Vectored Interupt support");
  850. set_vi_handler(MIPS_CPU_IPI_IRQ, ipi_irq_dispatch);
  851. irq_ipi.handler = ipi_interrupt;
  852. irq_ipi.flags = IRQF_DISABLED;
  853. irq_ipi.name = "SMTC_IPI";
  854. setup_irq_smtc(cpu_ipi_irq, &irq_ipi, (0x100 << MIPS_CPU_IPI_IRQ));
  855. irq_desc[cpu_ipi_irq].status |= IRQ_PER_CPU;
  856. set_irq_handler(cpu_ipi_irq, handle_percpu_irq);
  857. }
  858. /*
  859. * SMTC-specific hacks invoked from elsewhere in the kernel.
  860. */
  861. void smtc_ipi_replay(void)
  862. {
  863. /*
  864. * To the extent that we've ever turned interrupts off,
  865. * we may have accumulated deferred IPIs. This is subtle.
  866. * If we use the smtc_ipi_qdepth() macro, we'll get an
  867. * exact number - but we'll also disable interrupts
  868. * and create a window of failure where a new IPI gets
  869. * queued after we test the depth but before we re-enable
  870. * interrupts. So long as IXMT never gets set, however,
  871. * we should be OK: If we pick up something and dispatch
  872. * it here, that's great. If we see nothing, but concurrent
  873. * with this operation, another TC sends us an IPI, IXMT
  874. * is clear, and we'll handle it as a real pseudo-interrupt
  875. * and not a pseudo-pseudo interrupt.
  876. */
  877. if (IPIQ[smp_processor_id()].depth > 0) {
  878. struct smtc_ipi *pipi;
  879. extern void self_ipi(struct smtc_ipi *);
  880. while ((pipi = smtc_ipi_dq(&IPIQ[smp_processor_id()]))) {
  881. self_ipi(pipi);
  882. smtc_cpu_stats[smp_processor_id()].selfipis++;
  883. }
  884. }
  885. }
  886. EXPORT_SYMBOL(smtc_ipi_replay);
  887. void smtc_idle_loop_hook(void)
  888. {
  889. #ifdef CONFIG_SMTC_IDLE_HOOK_DEBUG
  890. int im;
  891. int flags;
  892. int mtflags;
  893. int bit;
  894. int vpe;
  895. int tc;
  896. int hook_ntcs;
  897. /*
  898. * printk within DMT-protected regions can deadlock,
  899. * so buffer diagnostic messages for later output.
  900. */
  901. char *pdb_msg;
  902. char id_ho_db_msg[768]; /* worst-case use should be less than 700 */
  903. if (atomic_read(&idle_hook_initialized) == 0) { /* fast test */
  904. if (atomic_add_return(1, &idle_hook_initialized) == 1) {
  905. int mvpconf0;
  906. /* Tedious stuff to just do once */
  907. mvpconf0 = read_c0_mvpconf0();
  908. hook_ntcs = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
  909. if (hook_ntcs > NR_CPUS)
  910. hook_ntcs = NR_CPUS;
  911. for (tc = 0; tc < hook_ntcs; tc++) {
  912. tcnoprog[tc] = 0;
  913. clock_hang_reported[tc] = 0;
  914. }
  915. for (vpe = 0; vpe < 2; vpe++)
  916. for (im = 0; im < 8; im++)
  917. imstuckcount[vpe][im] = 0;
  918. printk("Idle loop test hook initialized for %d TCs\n", hook_ntcs);
  919. atomic_set(&idle_hook_initialized, 1000);
  920. } else {
  921. /* Someone else is initializing in parallel - let 'em finish */
  922. while (atomic_read(&idle_hook_initialized) < 1000)
  923. ;
  924. }
  925. }
  926. /* Have we stupidly left IXMT set somewhere? */
  927. if (read_c0_tcstatus() & 0x400) {
  928. write_c0_tcstatus(read_c0_tcstatus() & ~0x400);
  929. ehb();
  930. printk("Dangling IXMT in cpu_idle()\n");
  931. }
  932. /* Have we stupidly left an IM bit turned off? */
  933. #define IM_LIMIT 2000
  934. local_irq_save(flags);
  935. mtflags = dmt();
  936. pdb_msg = &id_ho_db_msg[0];
  937. im = read_c0_status();
  938. vpe = cpu_data[smp_processor_id()].vpe_id;
  939. for (bit = 0; bit < 8; bit++) {
  940. /*
  941. * In current prototype, I/O interrupts
  942. * are masked for VPE > 0
  943. */
  944. if (vpemask[vpe][bit]) {
  945. if (!(im & (0x100 << bit)))
  946. imstuckcount[vpe][bit]++;
  947. else
  948. imstuckcount[vpe][bit] = 0;
  949. if (imstuckcount[vpe][bit] > IM_LIMIT) {
  950. set_c0_status(0x100 << bit);
  951. ehb();
  952. imstuckcount[vpe][bit] = 0;
  953. pdb_msg += sprintf(pdb_msg,
  954. "Dangling IM %d fixed for VPE %d\n", bit,
  955. vpe);
  956. }
  957. }
  958. }
  959. /*
  960. * Now that we limit outstanding timer IPIs, check for hung TC
  961. */
  962. for (tc = 0; tc < NR_CPUS; tc++) {
  963. /* Don't check ourself - we'll dequeue IPIs just below */
  964. if ((tc != smp_processor_id()) &&
  965. ipi_timer_latch[tc] > timerq_limit) {
  966. if (clock_hang_reported[tc] == 0) {
  967. pdb_msg += sprintf(pdb_msg,
  968. "TC %d looks hung with timer latch at %d\n",
  969. tc, ipi_timer_latch[tc]);
  970. clock_hang_reported[tc]++;
  971. }
  972. }
  973. }
  974. emt(mtflags);
  975. local_irq_restore(flags);
  976. if (pdb_msg != &id_ho_db_msg[0])
  977. printk("CPU%d: %s", smp_processor_id(), id_ho_db_msg);
  978. #endif /* CONFIG_SMTC_IDLE_HOOK_DEBUG */
  979. /*
  980. * Replay any accumulated deferred IPIs. If "Instant Replay"
  981. * is in use, there should never be any.
  982. */
  983. #ifndef CONFIG_MIPS_MT_SMTC_INSTANT_REPLAY
  984. smtc_ipi_replay();
  985. #endif /* CONFIG_MIPS_MT_SMTC_INSTANT_REPLAY */
  986. }
  987. void smtc_soft_dump(void)
  988. {
  989. int i;
  990. printk("Counter Interrupts taken per CPU (TC)\n");
  991. for (i=0; i < NR_CPUS; i++) {
  992. printk("%d: %ld\n", i, smtc_cpu_stats[i].timerints);
  993. }
  994. printk("Self-IPI invocations:\n");
  995. for (i=0; i < NR_CPUS; i++) {
  996. printk("%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
  997. }
  998. smtc_ipi_qdump();
  999. printk("Timer IPI Backlogs:\n");
  1000. for (i=0; i < NR_CPUS; i++) {
  1001. printk("%d: %d\n", i, ipi_timer_latch[i]);
  1002. }
  1003. printk("%d Recoveries of \"stolen\" FPU\n",
  1004. atomic_read(&smtc_fpu_recoveries));
  1005. }
  1006. /*
  1007. * TLB management routines special to SMTC
  1008. */
  1009. void smtc_get_new_mmu_context(struct mm_struct *mm, unsigned long cpu)
  1010. {
  1011. unsigned long flags, mtflags, tcstat, prevhalt, asid;
  1012. int tlb, i;
  1013. /*
  1014. * It would be nice to be able to use a spinlock here,
  1015. * but this is invoked from within TLB flush routines
  1016. * that protect themselves with DVPE, so if a lock is
  1017. * held by another TC, it'll never be freed.
  1018. *
  1019. * DVPE/DMT must not be done with interrupts enabled,
  1020. * so even so most callers will already have disabled
  1021. * them, let's be really careful...
  1022. */
  1023. local_irq_save(flags);
  1024. if (smtc_status & SMTC_TLB_SHARED) {
  1025. mtflags = dvpe();
  1026. tlb = 0;
  1027. } else {
  1028. mtflags = dmt();
  1029. tlb = cpu_data[cpu].vpe_id;
  1030. }
  1031. asid = asid_cache(cpu);
  1032. do {
  1033. if (!((asid += ASID_INC) & ASID_MASK) ) {
  1034. if (cpu_has_vtag_icache)
  1035. flush_icache_all();
  1036. /* Traverse all online CPUs (hack requires contigous range) */
  1037. for (i = 0; i < num_online_cpus(); i++) {
  1038. /*
  1039. * We don't need to worry about our own CPU, nor those of
  1040. * CPUs who don't share our TLB.
  1041. */
  1042. if ((i != smp_processor_id()) &&
  1043. ((smtc_status & SMTC_TLB_SHARED) ||
  1044. (cpu_data[i].vpe_id == cpu_data[cpu].vpe_id))) {
  1045. settc(cpu_data[i].tc_id);
  1046. prevhalt = read_tc_c0_tchalt() & TCHALT_H;
  1047. if (!prevhalt) {
  1048. write_tc_c0_tchalt(TCHALT_H);
  1049. mips_ihb();
  1050. }
  1051. tcstat = read_tc_c0_tcstatus();
  1052. smtc_live_asid[tlb][(tcstat & ASID_MASK)] |= (asiduse)(0x1 << i);
  1053. if (!prevhalt)
  1054. write_tc_c0_tchalt(0);
  1055. }
  1056. }
  1057. if (!asid) /* fix version if needed */
  1058. asid = ASID_FIRST_VERSION;
  1059. local_flush_tlb_all(); /* start new asid cycle */
  1060. }
  1061. } while (smtc_live_asid[tlb][(asid & ASID_MASK)]);
  1062. /*
  1063. * SMTC shares the TLB within VPEs and possibly across all VPEs.
  1064. */
  1065. for (i = 0; i < num_online_cpus(); i++) {
  1066. if ((smtc_status & SMTC_TLB_SHARED) ||
  1067. (cpu_data[i].vpe_id == cpu_data[cpu].vpe_id))
  1068. cpu_context(i, mm) = asid_cache(i) = asid;
  1069. }
  1070. if (smtc_status & SMTC_TLB_SHARED)
  1071. evpe(mtflags);
  1072. else
  1073. emt(mtflags);
  1074. local_irq_restore(flags);
  1075. }
  1076. /*
  1077. * Invoked from macros defined in mmu_context.h
  1078. * which must already have disabled interrupts
  1079. * and done a DVPE or DMT as appropriate.
  1080. */
  1081. void smtc_flush_tlb_asid(unsigned long asid)
  1082. {
  1083. int entry;
  1084. unsigned long ehi;
  1085. entry = read_c0_wired();
  1086. /* Traverse all non-wired entries */
  1087. while (entry < current_cpu_data.tlbsize) {
  1088. write_c0_index(entry);
  1089. ehb();
  1090. tlb_read();
  1091. ehb();
  1092. ehi = read_c0_entryhi();
  1093. if ((ehi & ASID_MASK) == asid) {
  1094. /*
  1095. * Invalidate only entries with specified ASID,
  1096. * makiing sure all entries differ.
  1097. */
  1098. write_c0_entryhi(CKSEG0 + (entry << (PAGE_SHIFT + 1)));
  1099. write_c0_entrylo0(0);
  1100. write_c0_entrylo1(0);
  1101. mtc0_tlbw_hazard();
  1102. tlb_write_indexed();
  1103. }
  1104. entry++;
  1105. }
  1106. write_c0_index(PARKED_INDEX);
  1107. tlbw_use_hazard();
  1108. }
  1109. /*
  1110. * Support for single-threading cache flush operations.
  1111. */
  1112. static int halt_state_save[NR_CPUS];
  1113. /*
  1114. * To really, really be sure that nothing is being done
  1115. * by other TCs, halt them all. This code assumes that
  1116. * a DVPE has already been done, so while their Halted
  1117. * state is theoretically architecturally unstable, in
  1118. * practice, it's not going to change while we're looking
  1119. * at it.
  1120. */
  1121. void smtc_cflush_lockdown(void)
  1122. {
  1123. int cpu;
  1124. for_each_online_cpu(cpu) {
  1125. if (cpu != smp_processor_id()) {
  1126. settc(cpu_data[cpu].tc_id);
  1127. halt_state_save[cpu] = read_tc_c0_tchalt();
  1128. write_tc_c0_tchalt(TCHALT_H);
  1129. }
  1130. }
  1131. mips_ihb();
  1132. }
  1133. /* It would be cheating to change the cpu_online states during a flush! */
  1134. void smtc_cflush_release(void)
  1135. {
  1136. int cpu;
  1137. /*
  1138. * Start with a hazard barrier to ensure
  1139. * that all CACHE ops have played through.
  1140. */
  1141. mips_ihb();
  1142. for_each_online_cpu(cpu) {
  1143. if (cpu != smp_processor_id()) {
  1144. settc(cpu_data[cpu].tc_id);
  1145. write_tc_c0_tchalt(halt_state_save[cpu]);
  1146. }
  1147. }
  1148. mips_ihb();
  1149. }