smtc.c 33 KB

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