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