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> |
Thomas Bogendoerfer | b78e9d6 | 2020-01-09 13:33:40 +0100 | [diff] [blame] | 18 | #include <asm/sn/agent.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/sn/arch.h> |
| 20 | #include <asm/sn/gda.h> |
| 21 | #include <asm/sn/intr.h> |
| 22 | #include <asm/sn/klconfig.h> |
| 23 | #include <asm/sn/launch.h> |
| 24 | #include <asm/sn/mapped_kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/sn/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Thomas Bogendoerfer | 249be56 | 2019-10-22 18:13:11 +0200 | [diff] [blame] | 27 | #include "ip27-common.h" |
| 28 | |
Thomas Bogendoerfer | d6972bb | 2020-01-09 13:33:39 +0100 | [diff] [blame] | 29 | static int node_scan_cpus(nasid_t nasid, int highest) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | { |
Thomas Bogendoerfer | d6972bb | 2020-01-09 13:33:39 +0100 | [diff] [blame] | 31 | static int cpus_found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | lboard_t *brd; |
| 33 | klcpu_t *acpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | cpuid_t cpuid; |
| 35 | |
| 36 | brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27); |
| 37 | |
| 38 | do { |
| 39 | acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU); |
| 40 | while (acpu) { |
| 41 | cpuid = acpu->cpu_info.virtid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | /* Only let it join in if it's marked enabled */ |
| 43 | if ((acpu->cpu_info.flags & KLINFO_ENABLE) && |
Thomas Bogendoerfer | d6972bb | 2020-01-09 13:33:39 +0100 | [diff] [blame] | 44 | (cpus_found != NR_CPUS)) { |
Thomas Bogendoerfer | 4bf841e | 2019-10-03 14:27:24 +0200 | [diff] [blame] | 45 | if (cpuid > highest) |
| 46 | highest = cpuid; |
Rusty Russell | 0b5f9c0 | 2012-03-29 15:38:30 +1030 | [diff] [blame] | 47 | set_cpu_possible(cpuid, true); |
Thomas Bogendoerfer | d6972bb | 2020-01-09 13:33:39 +0100 | [diff] [blame] | 48 | cputonasid(cpus_found) = nasid; |
| 49 | cputoslice(cpus_found) = acpu->cpu_info.physid; |
Thomas Bogendoerfer | d31f9e64 | 2020-01-09 13:33:50 +0100 | [diff] [blame] | 50 | sn_cpu_info[cpus_found].p_speed = |
| 51 | acpu->cpu_speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | cpus_found++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
| 54 | acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu, |
| 55 | KLSTRUCT_CPU); |
| 56 | } |
| 57 | brd = KLCF_NEXT(brd); |
| 58 | if (!brd) |
| 59 | break; |
| 60 | |
| 61 | brd = find_lboard(brd, KLTYPE_IP27); |
| 62 | } while (brd); |
| 63 | |
| 64 | return highest; |
| 65 | } |
| 66 | |
| 67 | void cpu_node_probe(void) |
| 68 | { |
| 69 | int i, highest = 0; |
| 70 | gda_t *gdap = GDA; |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | nodes_clear(node_online_map); |
Thomas Bogendoerfer | c80b489 | 2019-10-30 11:51:44 +0100 | [diff] [blame] | 73 | for (i = 0; i < MAX_NUMNODES; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | nasid_t nasid = gdap->g_nasidtable[i]; |
| 75 | if (nasid == INVALID_NASID) |
| 76 | break; |
Thomas Bogendoerfer | 4bf841e | 2019-10-03 14:27:24 +0200 | [diff] [blame] | 77 | node_set_online(nasid); |
Thomas Bogendoerfer | d6972bb | 2020-01-09 13:33:39 +0100 | [diff] [blame] | 78 | highest = node_scan_cpus(nasid, highest); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | printk("Discovered %d cpus on %d nodes\n", highest + 1, num_online_nodes()); |
| 82 | } |
| 83 | |
Ralf Baechle | 39408c6 | 2005-02-13 23:10:08 +0000 | [diff] [blame] | 84 | static __init void intr_clear_all(nasid_t nasid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | int i; |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0); |
| 89 | REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0); |
| 90 | REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0); |
| 91 | REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0); |
Ralf Baechle | 39408c6 | 2005-02-13 23:10:08 +0000 | [diff] [blame] | 92 | |
| 93 | for (i = 0; i < 128; i++) |
| 94 | REMOTE_HUB_CLR_INTR(nasid, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 97 | static void ip27_send_ipi_single(int destid, unsigned int action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
| 99 | int irq; |
| 100 | |
| 101 | switch (action) { |
| 102 | case SMP_RESCHEDULE_YOURSELF: |
| 103 | irq = CPU_RESCHED_A_IRQ; |
| 104 | break; |
| 105 | case SMP_CALL_FUNCTION: |
| 106 | irq = CPU_CALL_A_IRQ; |
| 107 | break; |
| 108 | default: |
| 109 | panic("sendintr"); |
| 110 | } |
| 111 | |
| 112 | irq += cputoslice(destid); |
| 113 | |
| 114 | /* |
Thomas Bogendoerfer | 4bf841e | 2019-10-03 14:27:24 +0200 | [diff] [blame] | 115 | * Set the interrupt bit associated with the CPU we want to |
| 116 | * send the interrupt to. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | */ |
Thomas Bogendoerfer | 4bf841e | 2019-10-03 14:27:24 +0200 | [diff] [blame] | 118 | REMOTE_HUB_SEND_INTR(cpu_to_node(destid), irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 120 | |
Ralf Baechle | b533e65 | 2009-09-25 15:08:01 +0100 | [diff] [blame] | 121 | 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] | 122 | { |
| 123 | unsigned int i; |
| 124 | |
Rusty Russell | 48a048f | 2009-09-24 09:34:44 -0600 | [diff] [blame] | 125 | for_each_cpu(i, mask) |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 126 | ip27_send_ipi_single(i, action); |
| 127 | } |
| 128 | |
Thomas Bogendoerfer | 2c86562 | 2019-02-19 16:57:19 +0100 | [diff] [blame] | 129 | static void ip27_init_cpu(void) |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 130 | { |
| 131 | per_cpu_init(); |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Paul Gortmaker | 078a55f | 2013-06-18 13:38:59 +0000 | [diff] [blame] | 134 | static void ip27_smp_finish(void) |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 135 | { |
Thomas Bogendoerfer | b32bb80 | 2008-04-08 23:43:57 +0200 | [diff] [blame] | 136 | hub_rt_clock_event_init(); |
| 137 | local_irq_enable(); |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 140 | /* |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 141 | * 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] | 142 | * set sp to the kernel stack of the newly created idle process, gp to the proc |
| 143 | * struct so that current_thread_info() will work. |
| 144 | */ |
Paul Burton | d595d42 | 2017-08-12 19:49:40 -0700 | [diff] [blame] | 145 | static int ip27_boot_secondary(int cpu, struct task_struct *idle) |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 146 | { |
| 147 | unsigned long gp = (unsigned long)task_thread_info(idle); |
| 148 | unsigned long sp = __KSTK_TOS(idle); |
| 149 | |
| 150 | LAUNCH_SLAVE(cputonasid(cpu), cputoslice(cpu), |
| 151 | (launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap), |
| 152 | 0, (void *) sp, (void *) gp); |
Paul Burton | d595d42 | 2017-08-12 19:49:40 -0700 | [diff] [blame] | 153 | return 0; |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static void __init ip27_smp_setup(void) |
| 157 | { |
Thomas Bogendoerfer | 4bf841e | 2019-10-03 14:27:24 +0200 | [diff] [blame] | 158 | nasid_t nasid; |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 159 | |
Thomas Bogendoerfer | 4bf841e | 2019-10-03 14:27:24 +0200 | [diff] [blame] | 160 | for_each_online_node(nasid) { |
| 161 | if (nasid == 0) |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 162 | continue; |
Thomas Bogendoerfer | 4bf841e | 2019-10-03 14:27:24 +0200 | [diff] [blame] | 163 | intr_clear_all(nasid); |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | replicate_kernel_text(); |
| 167 | |
| 168 | /* |
Thomas Bogendoerfer | 4bf841e | 2019-10-03 14:27:24 +0200 | [diff] [blame] | 169 | * PROM sets up system, that boot cpu is always first CPU on nasid 0 |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 170 | */ |
Thomas Bogendoerfer | d6972bb | 2020-01-09 13:33:39 +0100 | [diff] [blame] | 171 | cputonasid(0) = 0; |
| 172 | cputoslice(0) = LOCAL_HUB_L(PI_CPU_NUM); |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static void __init ip27_prepare_cpus(unsigned int max_cpus) |
| 176 | { |
| 177 | /* We already did everything necessary earlier */ |
| 178 | } |
| 179 | |
Matt Redfearn | ff2c825 | 2017-07-19 09:21:03 +0100 | [diff] [blame] | 180 | const struct plat_smp_ops ip27_smp_ops = { |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 181 | .send_ipi_single = ip27_send_ipi_single, |
| 182 | .send_ipi_mask = ip27_send_ipi_mask, |
Thomas Bogendoerfer | 2c86562 | 2019-02-19 16:57:19 +0100 | [diff] [blame] | 183 | .init_secondary = ip27_init_cpu, |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 184 | .smp_finish = ip27_smp_finish, |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 185 | .boot_secondary = ip27_boot_secondary, |
| 186 | .smp_setup = ip27_smp_setup, |
| 187 | .prepare_cpus = ip27_prepare_cpus, |
Thomas Bogendoerfer | 2c86562 | 2019-02-19 16:57:19 +0100 | [diff] [blame] | 188 | .prepare_boot_cpu = ip27_init_cpu, |
Ralf Baechle | 87353d8 | 2007-11-19 12:23:51 +0000 | [diff] [blame] | 189 | }; |