smp.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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/haldefs.h>
  43. #include <asm/netlogic/common.h>
  44. #include <asm/netlogic/xlr/iomap.h>
  45. #include <asm/netlogic/xlr/pic.h>
  46. void nlm_send_ipi_single(int logical_cpu, unsigned int action)
  47. {
  48. int cpu = cpu_logical_map(logical_cpu);
  49. if (action & SMP_CALL_FUNCTION)
  50. nlm_pic_send_ipi(nlm_pic_base, cpu, IRQ_IPI_SMP_FUNCTION, 0);
  51. if (action & SMP_RESCHEDULE_YOURSELF)
  52. nlm_pic_send_ipi(nlm_pic_base, cpu, IRQ_IPI_SMP_RESCHEDULE, 0);
  53. }
  54. void nlm_send_ipi_mask(const struct cpumask *mask, unsigned int action)
  55. {
  56. int cpu;
  57. for_each_cpu(cpu, mask) {
  58. nlm_send_ipi_single(cpu, action);
  59. }
  60. }
  61. /* IRQ_IPI_SMP_FUNCTION Handler */
  62. void nlm_smp_function_ipi_handler(unsigned int irq, struct irq_desc *desc)
  63. {
  64. smp_call_function_interrupt();
  65. write_c0_eirr(1ull << irq);
  66. }
  67. /* IRQ_IPI_SMP_RESCHEDULE handler */
  68. void nlm_smp_resched_ipi_handler(unsigned int irq, struct irq_desc *desc)
  69. {
  70. scheduler_ipi();
  71. write_c0_eirr(1ull << irq);
  72. }
  73. /*
  74. * Called before going into mips code, early cpu init
  75. */
  76. void nlm_early_init_secondary(int cpu)
  77. {
  78. write_c0_ebase((uint32_t)nlm_common_ebase);
  79. #ifdef NLM_XLP
  80. if (cpu % 4 == 0)
  81. xlp_mmu_init();
  82. #endif
  83. }
  84. /*
  85. * Code to run on secondary just after probing the CPU
  86. */
  87. static void __cpuinit nlm_init_secondary(void)
  88. {
  89. nlm_smp_irq_init();
  90. }
  91. void nlm_smp_finish(void)
  92. {
  93. #ifdef notyet
  94. nlm_common_msgring_cpu_init();
  95. #endif
  96. local_irq_enable();
  97. }
  98. void nlm_cpus_done(void)
  99. {
  100. }
  101. /*
  102. * Boot all other cpus in the system, initialize them, and bring them into
  103. * the boot function
  104. */
  105. int nlm_cpu_unblock[NR_CPUS];
  106. int nlm_cpu_ready[NR_CPUS];
  107. unsigned long nlm_next_gp;
  108. unsigned long nlm_next_sp;
  109. cpumask_t phys_cpu_present_map;
  110. void nlm_boot_secondary(int logical_cpu, struct task_struct *idle)
  111. {
  112. unsigned long gp = (unsigned long)task_thread_info(idle);
  113. unsigned long sp = (unsigned long)__KSTK_TOS(idle);
  114. int cpu = cpu_logical_map(logical_cpu);
  115. nlm_next_sp = sp;
  116. nlm_next_gp = gp;
  117. /* barrier */
  118. __sync();
  119. nlm_cpu_unblock[cpu] = 1;
  120. }
  121. void __init nlm_smp_setup(void)
  122. {
  123. unsigned int boot_cpu;
  124. int num_cpus, i;
  125. boot_cpu = hard_smp_processor_id();
  126. cpus_clear(phys_cpu_present_map);
  127. cpu_set(boot_cpu, phys_cpu_present_map);
  128. __cpu_number_map[boot_cpu] = 0;
  129. __cpu_logical_map[0] = boot_cpu;
  130. cpu_set(0, cpu_possible_map);
  131. num_cpus = 1;
  132. for (i = 0; i < NR_CPUS; i++) {
  133. /*
  134. * nlm_cpu_ready array is not set for the boot_cpu,
  135. * it is only set for ASPs (see smpboot.S)
  136. */
  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. };