smp_mt.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. * Copyright (C) 2004, 2005 MIPS Technologies, Inc. All rights reserved.
  3. *
  4. * Elizabeth Clarke (beth@mips.com)
  5. *
  6. * This program is free software; you can distribute it and/or modify it
  7. * under the terms of the GNU General Public License (Version 2) as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  18. *
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/sched.h>
  22. #include <linux/cpumask.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/compiler.h>
  25. #include <asm/atomic.h>
  26. #include <asm/cpu.h>
  27. #include <asm/processor.h>
  28. #include <asm/system.h>
  29. #include <asm/hardirq.h>
  30. #include <asm/mmu_context.h>
  31. #include <asm/smp.h>
  32. #include <asm/time.h>
  33. #include <asm/mipsregs.h>
  34. #include <asm/mipsmtregs.h>
  35. #include <asm/cacheflush.h>
  36. #include <asm/mips-boards/maltaint.h>
  37. #define MIPS_CPU_IPI_RESCHED_IRQ 0
  38. #define MIPS_CPU_IPI_CALL_IRQ 1
  39. static int cpu_ipi_resched_irq, cpu_ipi_call_irq;
  40. #if 0
  41. static void dump_mtregisters(int vpe, int tc)
  42. {
  43. printk("vpe %d tc %d\n", vpe, tc);
  44. settc(tc);
  45. printk(" c0 status 0x%lx\n", read_vpe_c0_status());
  46. printk(" vpecontrol 0x%lx\n", read_vpe_c0_vpecontrol());
  47. printk(" vpeconf0 0x%lx\n", read_vpe_c0_vpeconf0());
  48. printk(" tcstatus 0x%lx\n", read_tc_c0_tcstatus());
  49. printk(" tcrestart 0x%lx\n", read_tc_c0_tcrestart());
  50. printk(" tcbind 0x%lx\n", read_tc_c0_tcbind());
  51. printk(" tchalt 0x%lx\n", read_tc_c0_tchalt());
  52. }
  53. #endif
  54. void __init sanitize_tlb_entries(void)
  55. {
  56. int i, tlbsiz;
  57. unsigned long mvpconf0, ncpu;
  58. if (!cpu_has_mipsmt)
  59. return;
  60. set_c0_mvpcontrol(MVPCONTROL_VPC);
  61. back_to_back_c0_hazard();
  62. /* Disable TLB sharing */
  63. clear_c0_mvpcontrol(MVPCONTROL_STLB);
  64. mvpconf0 = read_c0_mvpconf0();
  65. printk(KERN_INFO "MVPConf0 0x%lx TLBS %lx PTLBE %ld\n", mvpconf0,
  66. (mvpconf0 & MVPCONF0_TLBS) >> MVPCONF0_TLBS_SHIFT,
  67. (mvpconf0 & MVPCONF0_PTLBE) >> MVPCONF0_PTLBE_SHIFT);
  68. tlbsiz = (mvpconf0 & MVPCONF0_PTLBE) >> MVPCONF0_PTLBE_SHIFT;
  69. ncpu = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
  70. printk(" tlbsiz %d ncpu %ld\n", tlbsiz, ncpu);
  71. if (tlbsiz > 0) {
  72. /* share them out across the vpe's */
  73. tlbsiz /= ncpu;
  74. printk(KERN_INFO "setting Config1.MMU_size to %d\n", tlbsiz);
  75. for (i = 0; i < ncpu; i++) {
  76. settc(i);
  77. if (i == 0)
  78. write_c0_config1((read_c0_config1() & ~(0x3f << 25)) | (tlbsiz << 25));
  79. else
  80. write_vpe_c0_config1((read_vpe_c0_config1() & ~(0x3f << 25)) |
  81. (tlbsiz << 25));
  82. }
  83. }
  84. clear_c0_mvpcontrol(MVPCONTROL_VPC);
  85. }
  86. static void ipi_resched_dispatch (struct pt_regs *regs)
  87. {
  88. do_IRQ(MIPS_CPU_IPI_RESCHED_IRQ, regs);
  89. }
  90. static void ipi_call_dispatch (struct pt_regs *regs)
  91. {
  92. do_IRQ(MIPS_CPU_IPI_CALL_IRQ, regs);
  93. }
  94. irqreturn_t ipi_resched_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  95. {
  96. return IRQ_HANDLED;
  97. }
  98. irqreturn_t ipi_call_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  99. {
  100. smp_call_function_interrupt();
  101. return IRQ_HANDLED;
  102. }
  103. static struct irqaction irq_resched = {
  104. .handler = ipi_resched_interrupt,
  105. .flags = SA_INTERRUPT,
  106. .name = "IPI_resched"
  107. };
  108. static struct irqaction irq_call = {
  109. .handler = ipi_call_interrupt,
  110. .flags = SA_INTERRUPT,
  111. .name = "IPI_call"
  112. };
  113. /*
  114. * Common setup before any secondaries are started
  115. * Make sure all CPU's are in a sensible state before we boot any of the
  116. * secondarys
  117. */
  118. void plat_smp_setup(void)
  119. {
  120. unsigned long val;
  121. int i, num;
  122. if (!cpu_has_mipsmt)
  123. return;
  124. /* disable MT so we can configure */
  125. dvpe();
  126. dmt();
  127. /* Put MVPE's into 'configuration state' */
  128. set_c0_mvpcontrol(MVPCONTROL_VPC);
  129. val = read_c0_mvpconf0();
  130. /* we'll always have more TC's than VPE's, so loop setting everything
  131. to a sensible state */
  132. for (i = 0, num = 0; i <= ((val & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT); i++) {
  133. settc(i);
  134. /* VPE's */
  135. if (i <= ((val & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT)) {
  136. /* deactivate all but vpe0 */
  137. if (i != 0) {
  138. unsigned long tmp = read_vpe_c0_vpeconf0();
  139. tmp &= ~VPECONF0_VPA;
  140. /* master VPE */
  141. tmp |= VPECONF0_MVP;
  142. write_vpe_c0_vpeconf0(tmp);
  143. /* Record this as available CPU */
  144. cpu_set(i, phys_cpu_present_map);
  145. __cpu_number_map[i] = ++num;
  146. __cpu_logical_map[num] = i;
  147. }
  148. /* disable multi-threading with TC's */
  149. write_vpe_c0_vpecontrol(read_vpe_c0_vpecontrol() & ~VPECONTROL_TE);
  150. if (i != 0) {
  151. write_vpe_c0_status((read_c0_status() & ~(ST0_IM | ST0_IE | ST0_KSU)) | ST0_CU0);
  152. write_vpe_c0_cause(read_vpe_c0_cause() & ~CAUSEF_IP);
  153. /* set config to be the same as vpe0, particularly kseg0 coherency alg */
  154. write_vpe_c0_config( read_c0_config());
  155. /* Propagate Config7 */
  156. write_vpe_c0_config7(read_c0_config7());
  157. }
  158. }
  159. /* TC's */
  160. if (i != 0) {
  161. unsigned long tmp;
  162. /* bind a TC to each VPE, May as well put all excess TC's
  163. on the last VPE */
  164. if ( i >= (((val & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT)+1) )
  165. write_tc_c0_tcbind(read_tc_c0_tcbind() | ((val & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) );
  166. else {
  167. write_tc_c0_tcbind( read_tc_c0_tcbind() | i);
  168. /* and set XTC */
  169. write_vpe_c0_vpeconf0( read_vpe_c0_vpeconf0() | (i << VPECONF0_XTC_SHIFT));
  170. }
  171. tmp = read_tc_c0_tcstatus();
  172. /* mark not allocated and not dynamically allocatable */
  173. tmp &= ~(TCSTATUS_A | TCSTATUS_DA);
  174. tmp |= TCSTATUS_IXMT; /* interrupt exempt */
  175. write_tc_c0_tcstatus(tmp);
  176. write_tc_c0_tchalt(TCHALT_H);
  177. }
  178. }
  179. /* Release config state */
  180. clear_c0_mvpcontrol(MVPCONTROL_VPC);
  181. /* We'll wait until starting the secondaries before starting MVPE */
  182. printk(KERN_INFO "Detected %i available secondary CPU(s)\n", num);
  183. /* set up ipi interrupts */
  184. if (cpu_has_vint) {
  185. set_vi_handler (MIPS_CPU_IPI_RESCHED_IRQ, ipi_resched_dispatch);
  186. set_vi_handler (MIPS_CPU_IPI_CALL_IRQ, ipi_call_dispatch);
  187. }
  188. }
  189. void __init plat_prepare_cpus(unsigned int max_cpus)
  190. {
  191. cpu_ipi_resched_irq = MIPSCPU_INT_BASE + MIPS_CPU_IPI_RESCHED_IRQ;
  192. cpu_ipi_call_irq = MIPSCPU_INT_BASE + MIPS_CPU_IPI_CALL_IRQ;
  193. setup_irq(cpu_ipi_resched_irq, &irq_resched);
  194. setup_irq(cpu_ipi_call_irq, &irq_call);
  195. /* need to mark IPI's as IRQ_PER_CPU */
  196. irq_desc[cpu_ipi_resched_irq].status |= IRQ_PER_CPU;
  197. irq_desc[cpu_ipi_call_irq].status |= IRQ_PER_CPU;
  198. }
  199. /*
  200. * Setup the PC, SP, and GP of a secondary processor and start it
  201. * running!
  202. * smp_bootstrap is the place to resume from
  203. * __KSTK_TOS(idle) is apparently the stack pointer
  204. * (unsigned long)idle->thread_info the gp
  205. * assumes a 1:1 mapping of TC => VPE
  206. */
  207. void prom_boot_secondary(int cpu, struct task_struct *idle)
  208. {
  209. struct thread_info *gp = task_thread_info(idle);
  210. dvpe();
  211. set_c0_mvpcontrol(MVPCONTROL_VPC);
  212. settc(cpu);
  213. /* restart */
  214. write_tc_c0_tcrestart((unsigned long)&smp_bootstrap);
  215. /* enable the tc this vpe/cpu will be running */
  216. write_tc_c0_tcstatus((read_tc_c0_tcstatus() & ~TCSTATUS_IXMT) | TCSTATUS_A);
  217. write_tc_c0_tchalt(0);
  218. /* enable the VPE */
  219. write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() | VPECONF0_VPA);
  220. /* stack pointer */
  221. write_tc_gpr_sp( __KSTK_TOS(idle));
  222. /* global pointer */
  223. write_tc_gpr_gp((unsigned long)gp);
  224. flush_icache_range((unsigned long)gp, (unsigned long)(gp + 1));
  225. /* finally out of configuration and into chaos */
  226. clear_c0_mvpcontrol(MVPCONTROL_VPC);
  227. evpe(EVPE_ENABLE);
  228. }
  229. void prom_init_secondary(void)
  230. {
  231. write_c0_status((read_c0_status() & ~ST0_IM ) |
  232. (STATUSF_IP0 | STATUSF_IP1 | STATUSF_IP7));
  233. }
  234. void prom_smp_finish(void)
  235. {
  236. write_c0_compare(read_c0_count() + (8* mips_hpt_frequency/HZ));
  237. local_irq_enable();
  238. }
  239. void prom_cpus_done(void)
  240. {
  241. }
  242. void core_send_ipi(int cpu, unsigned int action)
  243. {
  244. int i;
  245. unsigned long flags;
  246. int vpflags;
  247. local_irq_save (flags);
  248. vpflags = dvpe(); /* cant access the other CPU's registers whilst MVPE enabled */
  249. switch (action) {
  250. case SMP_CALL_FUNCTION:
  251. i = C_SW1;
  252. break;
  253. case SMP_RESCHEDULE_YOURSELF:
  254. default:
  255. i = C_SW0;
  256. break;
  257. }
  258. /* 1:1 mapping of vpe and tc... */
  259. settc(cpu);
  260. write_vpe_c0_cause(read_vpe_c0_cause() | i);
  261. evpe(vpflags);
  262. local_irq_restore(flags);
  263. }