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