smtc.c 33 KB

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