smtc.c 33 KB

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