smp.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * SMP support for Hexagon
  3. *
  4. * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #include <linux/err.h>
  21. #include <linux/errno.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/module.h>
  26. #include <linux/percpu.h>
  27. #include <linux/sched.h>
  28. #include <linux/smp.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/cpu.h>
  31. #include <asm/time.h> /* timer_interrupt */
  32. #include <asm/hexagon_vm.h>
  33. #define BASE_IPI_IRQ 26
  34. /*
  35. * cpu_possible_mask needs to be filled out prior to setup_per_cpu_areas
  36. * (which is prior to any of our smp_prepare_cpu crap), in order to set
  37. * up the... per_cpu areas.
  38. */
  39. struct ipi_data {
  40. unsigned long bits;
  41. };
  42. static DEFINE_PER_CPU(struct ipi_data, ipi_data);
  43. static inline void __handle_ipi(unsigned long *ops, struct ipi_data *ipi,
  44. int cpu)
  45. {
  46. unsigned long msg = 0;
  47. do {
  48. msg = find_next_bit(ops, BITS_PER_LONG, msg+1);
  49. switch (msg) {
  50. case IPI_TIMER:
  51. ipi_timer();
  52. break;
  53. case IPI_CALL_FUNC:
  54. generic_smp_call_function_interrupt();
  55. break;
  56. case IPI_CALL_FUNC_SINGLE:
  57. generic_smp_call_function_single_interrupt();
  58. break;
  59. case IPI_CPU_STOP:
  60. /*
  61. * call vmstop()
  62. */
  63. __vmstop();
  64. break;
  65. case IPI_RESCHEDULE:
  66. scheduler_ipi();
  67. break;
  68. }
  69. } while (msg < BITS_PER_LONG);
  70. }
  71. /* Used for IPI call from other CPU's to unmask int */
  72. void smp_vm_unmask_irq(void *info)
  73. {
  74. __vmintop_locen((long) info);
  75. }
  76. /*
  77. * This is based on Alpha's IPI stuff.
  78. * Supposed to take (int, void*) as args now.
  79. * Specifically, first arg is irq, second is the irq_desc.
  80. */
  81. irqreturn_t handle_ipi(int irq, void *desc)
  82. {
  83. int cpu = smp_processor_id();
  84. struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
  85. unsigned long ops;
  86. while ((ops = xchg(&ipi->bits, 0)) != 0)
  87. __handle_ipi(&ops, ipi, cpu);
  88. return IRQ_HANDLED;
  89. }
  90. void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg)
  91. {
  92. unsigned long flags;
  93. unsigned long cpu;
  94. unsigned long retval;
  95. local_irq_save(flags);
  96. for_each_cpu(cpu, cpumask) {
  97. struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
  98. set_bit(msg, &ipi->bits);
  99. /* Possible barrier here */
  100. retval = __vmintop_post(BASE_IPI_IRQ+cpu);
  101. if (retval != 0) {
  102. printk(KERN_ERR "interrupt %ld not configured?\n",
  103. BASE_IPI_IRQ+cpu);
  104. }
  105. }
  106. local_irq_restore(flags);
  107. }
  108. static struct irqaction ipi_intdesc = {
  109. .handler = handle_ipi,
  110. .flags = IRQF_TRIGGER_RISING,
  111. .name = "ipi_handler"
  112. };
  113. void __init smp_prepare_boot_cpu(void)
  114. {
  115. }
  116. /*
  117. * interrupts should already be disabled from the VM
  118. * SP should already be correct; need to set THREADINFO_REG
  119. * to point to current thread info
  120. */
  121. void __cpuinit start_secondary(void)
  122. {
  123. unsigned int cpu;
  124. unsigned long thread_ptr;
  125. /* Calculate thread_info pointer from stack pointer */
  126. __asm__ __volatile__(
  127. "%0 = SP;\n"
  128. : "=r" (thread_ptr)
  129. );
  130. thread_ptr = thread_ptr & ~(THREAD_SIZE-1);
  131. __asm__ __volatile__(
  132. QUOTED_THREADINFO_REG " = %0;\n"
  133. :
  134. : "r" (thread_ptr)
  135. );
  136. /* Set the memory struct */
  137. atomic_inc(&init_mm.mm_count);
  138. current->active_mm = &init_mm;
  139. cpu = smp_processor_id();
  140. setup_irq(BASE_IPI_IRQ + cpu, &ipi_intdesc);
  141. /* Register the clock_event dummy */
  142. setup_percpu_clockdev();
  143. printk(KERN_INFO "%s cpu %d\n", __func__, current_thread_info()->cpu);
  144. notify_cpu_starting(cpu);
  145. ipi_call_lock();
  146. set_cpu_online(cpu, true);
  147. ipi_call_unlock();
  148. local_irq_enable();
  149. cpu_idle();
  150. }
  151. /*
  152. * called once for each present cpu
  153. * apparently starts up the CPU and then
  154. * maintains control until "cpu_online(cpu)" is set.
  155. */
  156. int __cpuinit __cpu_up(unsigned int cpu)
  157. {
  158. struct task_struct *idle;
  159. struct thread_info *thread;
  160. void *stack_start;
  161. /* Create new init task for the CPU */
  162. idle = fork_idle(cpu);
  163. if (IS_ERR(idle))
  164. panic(KERN_ERR "fork_idle failed\n");
  165. thread = (struct thread_info *)idle->stack;
  166. thread->cpu = cpu;
  167. /* Boot to the head. */
  168. stack_start = ((void *) thread) + THREAD_SIZE;
  169. __vmstart(start_secondary, stack_start);
  170. while (!cpu_online(cpu))
  171. barrier();
  172. return 0;
  173. }
  174. void __init smp_cpus_done(unsigned int max_cpus)
  175. {
  176. }
  177. void __init smp_prepare_cpus(unsigned int max_cpus)
  178. {
  179. int i;
  180. /*
  181. * should eventually have some sort of machine
  182. * descriptor that has this stuff
  183. */
  184. /* Right now, let's just fake it. */
  185. for (i = 0; i < max_cpus; i++)
  186. set_cpu_present(i, true);
  187. /* Also need to register the interrupts for IPI */
  188. if (max_cpus > 1)
  189. setup_irq(BASE_IPI_IRQ, &ipi_intdesc);
  190. }
  191. void smp_send_reschedule(int cpu)
  192. {
  193. send_ipi(cpumask_of(cpu), IPI_RESCHEDULE);
  194. }
  195. void smp_send_stop(void)
  196. {
  197. struct cpumask targets;
  198. cpumask_copy(&targets, cpu_online_mask);
  199. cpumask_clear_cpu(smp_processor_id(), &targets);
  200. send_ipi(&targets, IPI_CPU_STOP);
  201. }
  202. void arch_send_call_function_single_ipi(int cpu)
  203. {
  204. send_ipi(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
  205. }
  206. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  207. {
  208. send_ipi(mask, IPI_CALL_FUNC);
  209. }
  210. int setup_profiling_timer(unsigned int multiplier)
  211. {
  212. return -EINVAL;
  213. }
  214. void smp_start_cpus(void)
  215. {
  216. int i;
  217. for (i = 0; i < NR_CPUS; i++)
  218. set_cpu_possible(i, true);
  219. }