smp.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
  3. * reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the NetLogic
  9. * license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  29. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  31. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  32. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <linux/kernel.h>
  35. #include <linux/delay.h>
  36. #include <linux/init.h>
  37. #include <linux/smp.h>
  38. #include <linux/irq.h>
  39. #include <asm/mmu_context.h>
  40. #include <asm/netlogic/interrupt.h>
  41. #include <asm/netlogic/mips-extns.h>
  42. #include <asm/netlogic/xlr/iomap.h>
  43. #include <asm/netlogic/xlr/pic.h>
  44. #include <asm/netlogic/xlr/xlr.h>
  45. void core_send_ipi(int logical_cpu, unsigned int action)
  46. {
  47. int cpu = cpu_logical_map(logical_cpu);
  48. u32 tid = cpu & 0x3;
  49. u32 pid = (cpu >> 2) & 0x07;
  50. u32 ipi = (tid << 16) | (pid << 20);
  51. if (action & SMP_CALL_FUNCTION)
  52. ipi |= IRQ_IPI_SMP_FUNCTION;
  53. else if (action & SMP_RESCHEDULE_YOURSELF)
  54. ipi |= IRQ_IPI_SMP_RESCHEDULE;
  55. else
  56. return;
  57. pic_send_ipi(ipi);
  58. }
  59. void nlm_send_ipi_single(int cpu, unsigned int action)
  60. {
  61. core_send_ipi(cpu, action);
  62. }
  63. void nlm_send_ipi_mask(const struct cpumask *mask, unsigned int action)
  64. {
  65. int cpu;
  66. for_each_cpu(cpu, mask) {
  67. core_send_ipi(cpu, action);
  68. }
  69. }
  70. /* IRQ_IPI_SMP_FUNCTION Handler */
  71. void nlm_smp_function_ipi_handler(unsigned int irq, struct irq_desc *desc)
  72. {
  73. smp_call_function_interrupt();
  74. }
  75. /* IRQ_IPI_SMP_RESCHEDULE handler */
  76. void nlm_smp_resched_ipi_handler(unsigned int irq, struct irq_desc *desc)
  77. {
  78. scheduler_ipi();
  79. }
  80. /*
  81. * Called before going into mips code, early cpu init
  82. */
  83. void nlm_early_init_secondary(void)
  84. {
  85. write_c0_ebase((uint32_t)nlm_common_ebase);
  86. /* TLB partition here later */
  87. }
  88. /*
  89. * Code to run on secondary just after probing the CPU
  90. */
  91. static void __cpuinit nlm_init_secondary(void)
  92. {
  93. nlm_smp_irq_init();
  94. }
  95. void nlm_smp_finish(void)
  96. {
  97. #ifdef notyet
  98. nlm_common_msgring_cpu_init();
  99. #endif
  100. local_irq_enable();
  101. }
  102. void nlm_cpus_done(void)
  103. {
  104. }
  105. /*
  106. * Boot all other cpus in the system, initialize them, and bring them into
  107. * the boot function
  108. */
  109. int nlm_cpu_unblock[NR_CPUS];
  110. int nlm_cpu_ready[NR_CPUS];
  111. unsigned long nlm_next_gp;
  112. unsigned long nlm_next_sp;
  113. cpumask_t phys_cpu_present_map;
  114. void nlm_boot_secondary(int logical_cpu, struct task_struct *idle)
  115. {
  116. unsigned long gp = (unsigned long)task_thread_info(idle);
  117. unsigned long sp = (unsigned long)__KSTK_TOS(idle);
  118. int cpu = cpu_logical_map(logical_cpu);
  119. nlm_next_sp = sp;
  120. nlm_next_gp = gp;
  121. /* barrier */
  122. __sync();
  123. nlm_cpu_unblock[cpu] = 1;
  124. }
  125. void __init nlm_smp_setup(void)
  126. {
  127. unsigned int boot_cpu;
  128. int num_cpus, i;
  129. boot_cpu = hard_smp_processor_id();
  130. cpus_clear(phys_cpu_present_map);
  131. cpu_set(boot_cpu, phys_cpu_present_map);
  132. __cpu_number_map[boot_cpu] = 0;
  133. __cpu_logical_map[0] = boot_cpu;
  134. cpu_set(0, cpu_possible_map);
  135. num_cpus = 1;
  136. for (i = 0; i < NR_CPUS; i++) {
  137. if (nlm_cpu_ready[i]) {
  138. cpu_set(i, phys_cpu_present_map);
  139. __cpu_number_map[i] = num_cpus;
  140. __cpu_logical_map[num_cpus] = i;
  141. cpu_set(num_cpus, cpu_possible_map);
  142. ++num_cpus;
  143. }
  144. }
  145. pr_info("Phys CPU present map: %lx, possible map %lx\n",
  146. (unsigned long)phys_cpu_present_map.bits[0],
  147. (unsigned long)cpu_possible_map.bits[0]);
  148. pr_info("Detected %i Slave CPU(s)\n", num_cpus);
  149. }
  150. void nlm_prepare_cpus(unsigned int max_cpus)
  151. {
  152. }
  153. struct plat_smp_ops nlm_smp_ops = {
  154. .send_ipi_single = nlm_send_ipi_single,
  155. .send_ipi_mask = nlm_send_ipi_mask,
  156. .init_secondary = nlm_init_secondary,
  157. .smp_finish = nlm_smp_finish,
  158. .cpus_done = nlm_cpus_done,
  159. .boot_secondary = nlm_boot_secondary,
  160. .smp_setup = nlm_smp_setup,
  161. .prepare_cpus = nlm_prepare_cpus,
  162. };
  163. unsigned long secondary_entry_point;
  164. int nlm_wakeup_secondary_cpus(u32 wakeup_mask)
  165. {
  166. unsigned int tid, pid, ipi, i, boot_cpu;
  167. void *reset_vec;
  168. secondary_entry_point = (unsigned long)prom_pre_boot_secondary_cpus;
  169. reset_vec = (void *)CKSEG1ADDR(0x1fc00000);
  170. memcpy(reset_vec, nlm_boot_smp_nmi, 0x80);
  171. boot_cpu = hard_smp_processor_id();
  172. for (i = 0; i < NR_CPUS; i++) {
  173. if (i == boot_cpu)
  174. continue;
  175. if (wakeup_mask & (1u << i)) {
  176. tid = i & 0x3;
  177. pid = (i >> 2) & 0x7;
  178. ipi = (tid << 16) | (pid << 20) | (1 << 8);
  179. pic_send_ipi(ipi);
  180. }
  181. }
  182. return 0;
  183. }