blob: c38df7c62964d915753f693db90ef241e8d26394 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Bergmannfc699102017-03-08 08:29:31 +010011#include <linux/sched/task_stack.h>
Ingo Molnaree6a3d12017-02-06 10:01:09 +010012#include <linux/topology.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/nodemask.h>
Arnd Bergmannfc699102017-03-08 08:29:31 +010014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/page.h>
16#include <asm/processor.h>
Arnd Bergmannfc699102017-03-08 08:29:31 +010017#include <asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#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
Thomas Bogendoerfer249be562019-10-22 18:13:11 +020030#include "ip27-common.h"
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/*
33 * Takes as first input the PROM assigned cpu id, and the kernel
34 * assigned cpu id as the second.
35 */
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +020036static void alloc_cpupda(nasid_t nasid, cpuid_t cpu, int cpunum)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 cputonasid(cpunum) = nasid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 cputoslice(cpunum) = get_cpu_slice(cpu);
40}
41
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +020042static int do_cpumask(nasid_t nasid, int highest)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 static int tot_cpus_found = 0;
45 lboard_t *brd;
46 klcpu_t *acpu;
47 int cpus_found = 0;
48 cpuid_t cpuid;
49
50 brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27);
51
52 do {
53 acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU);
54 while (acpu) {
55 cpuid = acpu->cpu_info.virtid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 /* Only let it join in if it's marked enabled */
57 if ((acpu->cpu_info.flags & KLINFO_ENABLE) &&
58 (tot_cpus_found != NR_CPUS)) {
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +020059 if (cpuid > highest)
60 highest = cpuid;
Rusty Russell0b5f9c02012-03-29 15:38:30 +103061 set_cpu_possible(cpuid, true);
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +020062 alloc_cpupda(nasid, cpuid, tot_cpus_found);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 cpus_found++;
64 tot_cpus_found++;
65 }
66 acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
67 KLSTRUCT_CPU);
68 }
69 brd = KLCF_NEXT(brd);
70 if (!brd)
71 break;
72
73 brd = find_lboard(brd, KLTYPE_IP27);
74 } while (brd);
75
76 return highest;
77}
78
79void cpu_node_probe(void)
80{
81 int i, highest = 0;
82 gda_t *gdap = GDA;
83
84 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 * MCD - this whole "compact node" stuff can probably be dropped,
86 * as we can handle sparse numbering now
87 */
88 nodes_clear(node_online_map);
89 for (i = 0; i < MAX_COMPACT_NODES; i++) {
90 nasid_t nasid = gdap->g_nasidtable[i];
91 if (nasid == INVALID_NASID)
92 break;
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +020093 node_set_online(nasid);
94 highest = do_cpumask(nasid, highest);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96
97 printk("Discovered %d cpus on %d nodes\n", highest + 1, num_online_nodes());
98}
99
Ralf Baechle39408c62005-02-13 23:10:08 +0000100static __init void intr_clear_all(nasid_t nasid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 int i;
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0);
105 REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0);
106 REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0);
107 REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0);
Ralf Baechle39408c62005-02-13 23:10:08 +0000108
109 for (i = 0; i < 128; i++)
110 REMOTE_HUB_CLR_INTR(nasid, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Ralf Baechle87353d82007-11-19 12:23:51 +0000113static void ip27_send_ipi_single(int destid, unsigned int action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115 int irq;
116
117 switch (action) {
118 case SMP_RESCHEDULE_YOURSELF:
119 irq = CPU_RESCHED_A_IRQ;
120 break;
121 case SMP_CALL_FUNCTION:
122 irq = CPU_CALL_A_IRQ;
123 break;
124 default:
125 panic("sendintr");
126 }
127
128 irq += cputoslice(destid);
129
130 /*
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200131 * Set the interrupt bit associated with the CPU we want to
132 * send the interrupt to.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 */
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200134 REMOTE_HUB_SEND_INTR(cpu_to_node(destid), irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
Ralf Baechle87353d82007-11-19 12:23:51 +0000136
Ralf Baechleb533e652009-09-25 15:08:01 +0100137static void ip27_send_ipi_mask(const struct cpumask *mask, unsigned int action)
Ralf Baechle87353d82007-11-19 12:23:51 +0000138{
139 unsigned int i;
140
Rusty Russell48a048f2009-09-24 09:34:44 -0600141 for_each_cpu(i, mask)
Ralf Baechle87353d82007-11-19 12:23:51 +0000142 ip27_send_ipi_single(i, action);
143}
144
Thomas Bogendoerfer2c865622019-02-19 16:57:19 +0100145static void ip27_init_cpu(void)
Ralf Baechle87353d82007-11-19 12:23:51 +0000146{
147 per_cpu_init();
Ralf Baechle87353d82007-11-19 12:23:51 +0000148}
149
Paul Gortmaker078a55f2013-06-18 13:38:59 +0000150static void ip27_smp_finish(void)
Ralf Baechle87353d82007-11-19 12:23:51 +0000151{
Thomas Bogendoerferb32bb802008-04-08 23:43:57 +0200152 hub_rt_clock_event_init();
153 local_irq_enable();
Ralf Baechle87353d82007-11-19 12:23:51 +0000154}
155
Ralf Baechle87353d82007-11-19 12:23:51 +0000156/*
Ralf Baechle70342282013-01-22 12:59:30 +0100157 * Launch a slave into smp_bootstrap(). It doesn't take an argument, and we
Ralf Baechle87353d82007-11-19 12:23:51 +0000158 * set sp to the kernel stack of the newly created idle process, gp to the proc
159 * struct so that current_thread_info() will work.
160 */
Paul Burtond595d422017-08-12 19:49:40 -0700161static int ip27_boot_secondary(int cpu, struct task_struct *idle)
Ralf Baechle87353d82007-11-19 12:23:51 +0000162{
163 unsigned long gp = (unsigned long)task_thread_info(idle);
164 unsigned long sp = __KSTK_TOS(idle);
165
166 LAUNCH_SLAVE(cputonasid(cpu), cputoslice(cpu),
167 (launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap),
168 0, (void *) sp, (void *) gp);
Paul Burtond595d422017-08-12 19:49:40 -0700169 return 0;
Ralf Baechle87353d82007-11-19 12:23:51 +0000170}
171
172static void __init ip27_smp_setup(void)
173{
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200174 nasid_t nasid;
Ralf Baechle87353d82007-11-19 12:23:51 +0000175
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200176 for_each_online_node(nasid) {
177 if (nasid == 0)
Ralf Baechle87353d82007-11-19 12:23:51 +0000178 continue;
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200179 intr_clear_all(nasid);
Ralf Baechle87353d82007-11-19 12:23:51 +0000180 }
181
182 replicate_kernel_text();
183
184 /*
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200185 * PROM sets up system, that boot cpu is always first CPU on nasid 0
Ralf Baechle87353d82007-11-19 12:23:51 +0000186 */
Thomas Bogendoerfer4bf841e2019-10-03 14:27:24 +0200187 alloc_cpupda(0, 0, 0);
Ralf Baechle87353d82007-11-19 12:23:51 +0000188}
189
190static void __init ip27_prepare_cpus(unsigned int max_cpus)
191{
192 /* We already did everything necessary earlier */
193}
194
Matt Redfearnff2c8252017-07-19 09:21:03 +0100195const struct plat_smp_ops ip27_smp_ops = {
Ralf Baechle87353d82007-11-19 12:23:51 +0000196 .send_ipi_single = ip27_send_ipi_single,
197 .send_ipi_mask = ip27_send_ipi_mask,
Thomas Bogendoerfer2c865622019-02-19 16:57:19 +0100198 .init_secondary = ip27_init_cpu,
Ralf Baechle87353d82007-11-19 12:23:51 +0000199 .smp_finish = ip27_smp_finish,
Ralf Baechle87353d82007-11-19 12:23:51 +0000200 .boot_secondary = ip27_boot_secondary,
201 .smp_setup = ip27_smp_setup,
202 .prepare_cpus = ip27_prepare_cpus,
Thomas Bogendoerfer2c865622019-02-19 16:57:19 +0100203 .prepare_boot_cpu = ip27_init_cpu,
Ralf Baechle87353d82007-11-19 12:23:51 +0000204};