smp.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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_CPU_STOP:
  57. /*
  58. * call vmstop()
  59. */
  60. __vmstop();
  61. break;
  62. case IPI_RESCHEDULE:
  63. scheduler_ipi();
  64. break;
  65. }
  66. } while (msg < BITS_PER_LONG);
  67. }
  68. /* Used for IPI call from other CPU's to unmask int */
  69. void smp_vm_unmask_irq(void *info)
  70. {
  71. __vmintop_locen((long) info);
  72. }
  73. /*
  74. * This is based on Alpha's IPI stuff.
  75. * Supposed to take (int, void*) as args now.
  76. * Specifically, first arg is irq, second is the irq_desc.
  77. */
  78. irqreturn_t handle_ipi(int irq, void *desc)
  79. {
  80. int cpu = smp_processor_id();
  81. struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
  82. unsigned long ops;
  83. while ((ops = xchg(&ipi->bits, 0)) != 0)
  84. __handle_ipi(&ops, ipi, cpu);
  85. return IRQ_HANDLED;
  86. }
  87. void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg)
  88. {
  89. unsigned long flags;
  90. unsigned long cpu;
  91. unsigned long retval;
  92. local_irq_save(flags);
  93. for_each_cpu(cpu, cpumask) {
  94. struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
  95. set_bit(msg, &ipi->bits);
  96. /* Possible barrier here */
  97. retval = __vmintop_post(BASE_IPI_IRQ+cpu);
  98. if (retval != 0) {
  99. printk(KERN_ERR "interrupt %ld not configured?\n",
  100. BASE_IPI_IRQ+cpu);
  101. }
  102. }
  103. local_irq_restore(flags);
  104. }
  105. static struct irqaction ipi_intdesc = {
  106. .handler = handle_ipi,
  107. .flags = IRQF_TRIGGER_RISING,
  108. .name = "ipi_handler"
  109. };
  110. void __init smp_prepare_boot_cpu(void)
  111. {
  112. }
  113. /*
  114. * interrupts should already be disabled from the VM
  115. * SP should already be correct; need to set THREADINFO_REG
  116. * to point to current thread info
  117. */
  118. void start_secondary(void)
  119. {
  120. unsigned int cpu;
  121. unsigned long thread_ptr;
  122. /* Calculate thread_info pointer from stack pointer */
  123. __asm__ __volatile__(
  124. "%0 = SP;\n"
  125. : "=r" (thread_ptr)
  126. );
  127. thread_ptr = thread_ptr & ~(THREAD_SIZE-1);
  128. __asm__ __volatile__(
  129. QUOTED_THREADINFO_REG " = %0;\n"
  130. :
  131. : "r" (thread_ptr)
  132. );
  133. /* Set the memory struct */
  134. atomic_inc(&init_mm.mm_count);
  135. current->active_mm = &init_mm;
  136. cpu = smp_processor_id();
  137. setup_irq(BASE_IPI_IRQ + cpu, &ipi_intdesc);
  138. /* Register the clock_event dummy */
  139. setup_percpu_clockdev();
  140. printk(KERN_INFO "%s cpu %d\n", __func__, current_thread_info()->cpu);
  141. notify_cpu_starting(cpu);
  142. set_cpu_online(cpu, true);
  143. local_irq_enable();
  144. cpu_startup_entry(CPUHP_ONLINE);
  145. }
  146. /*
  147. * called once for each present cpu
  148. * apparently starts up the CPU and then
  149. * maintains control until "cpu_online(cpu)" is set.
  150. */
  151. int __cpu_up(unsigned int cpu, struct task_struct *idle)
  152. {
  153. struct thread_info *thread = (struct thread_info *)idle->stack;
  154. void *stack_start;
  155. thread->cpu = cpu;
  156. /* Boot to the head. */
  157. stack_start = ((void *) thread) + THREAD_SIZE;
  158. __vmstart(start_secondary, stack_start);
  159. while (!cpu_online(cpu))
  160. barrier();
  161. return 0;
  162. }
  163. void __init smp_cpus_done(unsigned int max_cpus)
  164. {
  165. }
  166. void __init smp_prepare_cpus(unsigned int max_cpus)
  167. {
  168. int i;
  169. /*
  170. * should eventually have some sort of machine
  171. * descriptor that has this stuff
  172. */
  173. /* Right now, let's just fake it. */
  174. for (i = 0; i < max_cpus; i++)
  175. set_cpu_present(i, true);
  176. /* Also need to register the interrupts for IPI */
  177. if (max_cpus > 1)
  178. setup_irq(BASE_IPI_IRQ, &ipi_intdesc);
  179. }
  180. void smp_send_reschedule(int cpu)
  181. {
  182. send_ipi(cpumask_of(cpu), IPI_RESCHEDULE);
  183. }
  184. void smp_send_stop(void)
  185. {
  186. struct cpumask targets;
  187. cpumask_copy(&targets, cpu_online_mask);
  188. cpumask_clear_cpu(smp_processor_id(), &targets);
  189. send_ipi(&targets, IPI_CPU_STOP);
  190. }
  191. void arch_send_call_function_single_ipi(int cpu)
  192. {
  193. send_ipi(cpumask_of(cpu), IPI_CALL_FUNC);
  194. }
  195. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  196. {
  197. send_ipi(mask, IPI_CALL_FUNC);
  198. }
  199. int setup_profiling_timer(unsigned int multiplier)
  200. {
  201. return -EINVAL;
  202. }
  203. void smp_start_cpus(void)
  204. {
  205. int i;
  206. for (i = 0; i < NR_CPUS; i++)
  207. set_cpu_possible(i, true);
  208. }