ip27-smp.c 5.9 KB

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