ip27-smp.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 (kanoj@sgi.com)
  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/arch.h>
  18. #include <asm/sn/gda.h>
  19. #include <asm/sn/intr.h>
  20. #include <asm/sn/klconfig.h>
  21. #include <asm/sn/launch.h>
  22. #include <asm/sn/mapped_kernel.h>
  23. #include <asm/sn/sn_private.h>
  24. #include <asm/sn/types.h>
  25. #include <asm/sn/sn0/hubpi.h>
  26. #include <asm/sn/sn0/hubio.h>
  27. #include <asm/sn/sn0/ip27.h>
  28. /*
  29. * Takes as first input the PROM assigned cpu id, and the kernel
  30. * assigned cpu id as the second.
  31. */
  32. static void alloc_cpupda(cpuid_t cpu, int cpunum)
  33. {
  34. cnodeid_t node = get_cpu_cnode(cpu);
  35. nasid_t nasid = COMPACT_TO_NASID_NODEID(node);
  36. cputonasid(cpunum) = nasid;
  37. sn_cpu_info[cpunum].p_nodeid = node;
  38. cputoslice(cpunum) = get_cpu_slice(cpu);
  39. }
  40. static nasid_t get_actual_nasid(lboard_t *brd)
  41. {
  42. klhub_t *hub;
  43. if (!brd)
  44. return INVALID_NASID;
  45. /* find out if we are a completely disabled brd. */
  46. hub = (klhub_t *)find_first_component(brd, KLSTRUCT_HUB);
  47. if (!hub)
  48. return INVALID_NASID;
  49. if (!(hub->hub_info.flags & KLINFO_ENABLE)) /* disabled node brd */
  50. return hub->hub_info.physid;
  51. else
  52. return brd->brd_nasid;
  53. }
  54. static int do_cpumask(cnodeid_t cnode, nasid_t nasid, int highest)
  55. {
  56. static int tot_cpus_found = 0;
  57. lboard_t *brd;
  58. klcpu_t *acpu;
  59. int cpus_found = 0;
  60. cpuid_t cpuid;
  61. brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27);
  62. do {
  63. acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU);
  64. while (acpu) {
  65. cpuid = acpu->cpu_info.virtid;
  66. /* cnode is not valid for completely disabled brds */
  67. if (get_actual_nasid(brd) == brd->brd_nasid)
  68. cpuid_to_compact_node[cpuid] = cnode;
  69. if (cpuid > highest)
  70. highest = cpuid;
  71. /* Only let it join in if it's marked enabled */
  72. if ((acpu->cpu_info.flags & KLINFO_ENABLE) &&
  73. (tot_cpus_found != NR_CPUS)) {
  74. set_cpu_possible(cpuid, true);
  75. alloc_cpupda(cpuid, tot_cpus_found);
  76. cpus_found++;
  77. tot_cpus_found++;
  78. }
  79. acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
  80. KLSTRUCT_CPU);
  81. }
  82. brd = KLCF_NEXT(brd);
  83. if (!brd)
  84. break;
  85. brd = find_lboard(brd, KLTYPE_IP27);
  86. } while (brd);
  87. return highest;
  88. }
  89. void cpu_node_probe(void)
  90. {
  91. int i, highest = 0;
  92. gda_t *gdap = GDA;
  93. /*
  94. * Initialize the arrays to invalid nodeid (-1)
  95. */
  96. for (i = 0; i < MAX_COMPACT_NODES; i++)
  97. compact_to_nasid_node[i] = INVALID_NASID;
  98. for (i = 0; i < MAX_NASIDS; i++)
  99. nasid_to_compact_node[i] = INVALID_CNODEID;
  100. for (i = 0; i < MAXCPUS; i++)
  101. cpuid_to_compact_node[i] = INVALID_CNODEID;
  102. /*
  103. * MCD - this whole "compact node" stuff can probably be dropped,
  104. * as we can handle sparse numbering now
  105. */
  106. nodes_clear(node_online_map);
  107. for (i = 0; i < MAX_COMPACT_NODES; i++) {
  108. nasid_t nasid = gdap->g_nasidtable[i];
  109. if (nasid == INVALID_NASID)
  110. break;
  111. compact_to_nasid_node[i] = nasid;
  112. nasid_to_compact_node[nasid] = i;
  113. node_set_online(num_online_nodes());
  114. highest = do_cpumask(i, nasid, highest);
  115. }
  116. printk("Discovered %d cpus on %d nodes\n", highest + 1, num_online_nodes());
  117. }
  118. static __init void intr_clear_all(nasid_t nasid)
  119. {
  120. int i;
  121. REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0);
  122. REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0);
  123. REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0);
  124. REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0);
  125. for (i = 0; i < 128; i++)
  126. REMOTE_HUB_CLR_INTR(nasid, i);
  127. }
  128. static void ip27_send_ipi_single(int destid, unsigned int action)
  129. {
  130. int irq;
  131. switch (action) {
  132. case SMP_RESCHEDULE_YOURSELF:
  133. irq = CPU_RESCHED_A_IRQ;
  134. break;
  135. case SMP_CALL_FUNCTION:
  136. irq = CPU_CALL_A_IRQ;
  137. break;
  138. default:
  139. panic("sendintr");
  140. }
  141. irq += cputoslice(destid);
  142. /*
  143. * Convert the compact hub number to the NASID to get the correct
  144. * part of the address space. Then set the interrupt bit associated
  145. * with the CPU we want to send the interrupt to.
  146. */
  147. REMOTE_HUB_SEND_INTR(COMPACT_TO_NASID_NODEID(cpu_to_node(destid)), irq);
  148. }
  149. static void ip27_send_ipi_mask(const struct cpumask *mask, unsigned int action)
  150. {
  151. unsigned int i;
  152. for_each_cpu(i, mask)
  153. ip27_send_ipi_single(i, action);
  154. }
  155. static void ip27_init_secondary(void)
  156. {
  157. per_cpu_init();
  158. }
  159. static void ip27_smp_finish(void)
  160. {
  161. extern void hub_rt_clock_event_init(void);
  162. hub_rt_clock_event_init();
  163. local_irq_enable();
  164. }
  165. /*
  166. * Launch a slave into smp_bootstrap(). It doesn't take an argument, and we
  167. * set sp to the kernel stack of the newly created idle process, gp to the proc
  168. * struct so that current_thread_info() will work.
  169. */
  170. static int ip27_boot_secondary(int cpu, struct task_struct *idle)
  171. {
  172. unsigned long gp = (unsigned long)task_thread_info(idle);
  173. unsigned long sp = __KSTK_TOS(idle);
  174. LAUNCH_SLAVE(cputonasid(cpu), cputoslice(cpu),
  175. (launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap),
  176. 0, (void *) sp, (void *) gp);
  177. return 0;
  178. }
  179. static void __init ip27_smp_setup(void)
  180. {
  181. cnodeid_t cnode;
  182. for_each_online_node(cnode) {
  183. if (cnode == 0)
  184. continue;
  185. intr_clear_all(COMPACT_TO_NASID_NODEID(cnode));
  186. }
  187. replicate_kernel_text();
  188. /*
  189. * Assumption to be fixed: we're always booted on logical / physical
  190. * processor 0. While we're always running on logical processor 0
  191. * this still means this is physical processor zero; it might for
  192. * example be disabled in the firmware.
  193. */
  194. alloc_cpupda(0, 0);
  195. }
  196. static void __init ip27_prepare_cpus(unsigned int max_cpus)
  197. {
  198. /* We already did everything necessary earlier */
  199. }
  200. const struct plat_smp_ops ip27_smp_ops = {
  201. .send_ipi_single = ip27_send_ipi_single,
  202. .send_ipi_mask = ip27_send_ipi_mask,
  203. .init_secondary = ip27_init_secondary,
  204. .smp_finish = ip27_smp_finish,
  205. .boot_secondary = ip27_boot_secondary,
  206. .smp_setup = ip27_smp_setup,
  207. .prepare_cpus = ip27_prepare_cpus,
  208. };