ip27-smp.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General
  3. * Public License. See the file "COPYING" in the main directory of this
  4. * archive for more details.
  5. *
  6. * Copyright (C) 2000 - 2001 by Kanoj Sarcar ([email protected])
  7. * Copyright (C) 2000 - 2001 by Silicon Graphics, Inc.
  8. */
  9. #include <linux/init.h>
  10. #include <linux/sched.h>
  11. #include <linux/sched/task_stack.h>
  12. #include <linux/topology.h>
  13. #include <linux/nodemask.h>
  14. #include <asm/page.h>
  15. #include <asm/processor.h>
  16. #include <asm/ptrace.h>
  17. #include <asm/sn/agent.h>
  18. #include <asm/sn/arch.h>
  19. #include <asm/sn/gda.h>
  20. #include <asm/sn/intr.h>
  21. #include <asm/sn/klconfig.h>
  22. #include <asm/sn/launch.h>
  23. #include <asm/sn/mapped_kernel.h>
  24. #include <asm/sn/types.h>
  25. #include "ip27-common.h"
  26. static int node_scan_cpus(nasid_t nasid, int highest)
  27. {
  28. static int cpus_found;
  29. lboard_t *brd;
  30. klcpu_t *acpu;
  31. cpuid_t cpuid;
  32. brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27);
  33. do {
  34. acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU);
  35. while (acpu) {
  36. cpuid = acpu->cpu_info.virtid;
  37. /* Only let it join in if it's marked enabled */
  38. if ((acpu->cpu_info.flags & KLINFO_ENABLE) &&
  39. (cpus_found != NR_CPUS)) {
  40. if (cpuid > highest)
  41. highest = cpuid;
  42. set_cpu_possible(cpuid, true);
  43. cputonasid(cpus_found) = nasid;
  44. cputoslice(cpus_found) = acpu->cpu_info.physid;
  45. sn_cpu_info[cpus_found].p_speed =
  46. acpu->cpu_speed;
  47. cpus_found++;
  48. }
  49. acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
  50. KLSTRUCT_CPU);
  51. }
  52. brd = KLCF_NEXT(brd);
  53. if (!brd)
  54. break;
  55. brd = find_lboard(brd, KLTYPE_IP27);
  56. } while (brd);
  57. return highest;
  58. }
  59. void cpu_node_probe(void)
  60. {
  61. int i, highest = 0;
  62. gda_t *gdap = GDA;
  63. nodes_clear(node_online_map);
  64. for (i = 0; i < MAX_NUMNODES; i++) {
  65. nasid_t nasid = gdap->g_nasidtable[i];
  66. if (nasid == INVALID_NASID)
  67. break;
  68. node_set_online(nasid);
  69. highest = node_scan_cpus(nasid, highest);
  70. }
  71. printk("Discovered %d cpus on %d nodes\n", highest + 1, num_online_nodes());
  72. }
  73. static __init void intr_clear_all(nasid_t nasid)
  74. {
  75. int i;
  76. REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0);
  77. REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0);
  78. REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0);
  79. REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0);
  80. for (i = 0; i < 128; i++)
  81. REMOTE_HUB_CLR_INTR(nasid, i);
  82. }
  83. static void ip27_send_ipi_single(int destid, unsigned int action)
  84. {
  85. int irq;
  86. switch (action) {
  87. case SMP_RESCHEDULE_YOURSELF:
  88. irq = CPU_RESCHED_A_IRQ;
  89. break;
  90. case SMP_CALL_FUNCTION:
  91. irq = CPU_CALL_A_IRQ;
  92. break;
  93. default:
  94. panic("sendintr");
  95. }
  96. irq += cputoslice(destid);
  97. /*
  98. * Set the interrupt bit associated with the CPU we want to
  99. * send the interrupt to.
  100. */
  101. REMOTE_HUB_SEND_INTR(cpu_to_node(destid), irq);
  102. }
  103. static void ip27_send_ipi_mask(const struct cpumask *mask, unsigned int action)
  104. {
  105. unsigned int i;
  106. for_each_cpu(i, mask)
  107. ip27_send_ipi_single(i, action);
  108. }
  109. static void ip27_init_cpu(void)
  110. {
  111. per_cpu_init();
  112. }
  113. static void ip27_smp_finish(void)
  114. {
  115. hub_rt_clock_event_init();
  116. local_irq_enable();
  117. }
  118. /*
  119. * Launch a slave into smp_bootstrap(). It doesn't take an argument, and we
  120. * set sp to the kernel stack of the newly created idle process, gp to the proc
  121. * struct so that current_thread_info() will work.
  122. */
  123. static int ip27_boot_secondary(int cpu, struct task_struct *idle)
  124. {
  125. unsigned long gp = (unsigned long)task_thread_info(idle);
  126. unsigned long sp = __KSTK_TOS(idle);
  127. LAUNCH_SLAVE(cputonasid(cpu), cputoslice(cpu),
  128. (launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap),
  129. 0, (void *) sp, (void *) gp);
  130. return 0;
  131. }
  132. static void __init ip27_smp_setup(void)
  133. {
  134. nasid_t nasid;
  135. for_each_online_node(nasid) {
  136. if (nasid == 0)
  137. continue;
  138. intr_clear_all(nasid);
  139. }
  140. replicate_kernel_text();
  141. /*
  142. * PROM sets up system, that boot cpu is always first CPU on nasid 0
  143. */
  144. cputonasid(0) = 0;
  145. cputoslice(0) = LOCAL_HUB_L(PI_CPU_NUM);
  146. }
  147. static void __init ip27_prepare_cpus(unsigned int max_cpus)
  148. {
  149. /* We already did everything necessary earlier */
  150. }
  151. const struct plat_smp_ops ip27_smp_ops = {
  152. .send_ipi_single = ip27_send_ipi_single,
  153. .send_ipi_mask = ip27_send_ipi_mask,
  154. .init_secondary = ip27_init_cpu,
  155. .smp_finish = ip27_smp_finish,
  156. .boot_secondary = ip27_boot_secondary,
  157. .smp_setup = ip27_smp_setup,
  158. .prepare_cpus = ip27_prepare_cpus,
  159. .prepare_boot_cpu = ip27_init_cpu,
  160. };