smtc.c 32 KB

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