11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds * This file is subject to the terms and conditions of the GNU General
31da177e4SLinus Torvalds * Public License. See the file "COPYING" in the main directory of this
41da177e4SLinus Torvalds * archive for more details.
51da177e4SLinus Torvalds *
61da177e4SLinus Torvalds * Copyright (C) 2000 - 2001 by Kanoj Sarcar (kanoj@sgi.com)
71da177e4SLinus Torvalds * Copyright (C) 2000 - 2001 by Silicon Graphics, Inc.
81da177e4SLinus Torvalds */
91da177e4SLinus Torvalds #include <linux/init.h>
101da177e4SLinus Torvalds #include <linux/sched.h>
11fc69910fSArnd Bergmann #include <linux/sched/task_stack.h>
12ee6a3d19SIngo Molnar #include <linux/topology.h>
131da177e4SLinus Torvalds #include <linux/nodemask.h>
14fc69910fSArnd Bergmann
151da177e4SLinus Torvalds #include <asm/page.h>
161da177e4SLinus Torvalds #include <asm/processor.h>
17fc69910fSArnd Bergmann #include <asm/ptrace.h>
18b78e9d63SThomas Bogendoerfer #include <asm/sn/agent.h>
191da177e4SLinus Torvalds #include <asm/sn/arch.h>
201da177e4SLinus Torvalds #include <asm/sn/gda.h>
211da177e4SLinus Torvalds #include <asm/sn/intr.h>
221da177e4SLinus Torvalds #include <asm/sn/klconfig.h>
231da177e4SLinus Torvalds #include <asm/sn/launch.h>
241da177e4SLinus Torvalds #include <asm/sn/mapped_kernel.h>
251da177e4SLinus Torvalds #include <asm/sn/types.h>
261da177e4SLinus Torvalds
27249be563SThomas Bogendoerfer #include "ip27-common.h"
28249be563SThomas Bogendoerfer
node_scan_cpus(nasid_t nasid,int highest)29d6972bb4SThomas Bogendoerfer static int node_scan_cpus(nasid_t nasid, int highest)
301da177e4SLinus Torvalds {
31d6972bb4SThomas Bogendoerfer static int cpus_found;
321da177e4SLinus Torvalds lboard_t *brd;
331da177e4SLinus Torvalds klcpu_t *acpu;
341da177e4SLinus Torvalds cpuid_t cpuid;
351da177e4SLinus Torvalds
361da177e4SLinus Torvalds brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27);
371da177e4SLinus Torvalds
381da177e4SLinus Torvalds do {
391da177e4SLinus Torvalds acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU);
401da177e4SLinus Torvalds while (acpu) {
411da177e4SLinus Torvalds cpuid = acpu->cpu_info.virtid;
421da177e4SLinus Torvalds /* Only let it join in if it's marked enabled */
431da177e4SLinus Torvalds if ((acpu->cpu_info.flags & KLINFO_ENABLE) &&
44d6972bb4SThomas Bogendoerfer (cpus_found != NR_CPUS)) {
454bf841ebSThomas Bogendoerfer if (cpuid > highest)
464bf841ebSThomas Bogendoerfer highest = cpuid;
470b5f9c00SRusty Russell set_cpu_possible(cpuid, true);
48d6972bb4SThomas Bogendoerfer cputonasid(cpus_found) = nasid;
49d6972bb4SThomas Bogendoerfer cputoslice(cpus_found) = acpu->cpu_info.physid;
50d31f9e64SThomas Bogendoerfer sn_cpu_info[cpus_found].p_speed =
51d31f9e64SThomas Bogendoerfer acpu->cpu_speed;
521da177e4SLinus Torvalds cpus_found++;
531da177e4SLinus Torvalds }
541da177e4SLinus Torvalds acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
551da177e4SLinus Torvalds KLSTRUCT_CPU);
561da177e4SLinus Torvalds }
571da177e4SLinus Torvalds brd = KLCF_NEXT(brd);
581da177e4SLinus Torvalds if (!brd)
591da177e4SLinus Torvalds break;
601da177e4SLinus Torvalds
611da177e4SLinus Torvalds brd = find_lboard(brd, KLTYPE_IP27);
621da177e4SLinus Torvalds } while (brd);
631da177e4SLinus Torvalds
641da177e4SLinus Torvalds return highest;
651da177e4SLinus Torvalds }
661da177e4SLinus Torvalds
cpu_node_probe(void)671da177e4SLinus Torvalds void cpu_node_probe(void)
681da177e4SLinus Torvalds {
691da177e4SLinus Torvalds int i, highest = 0;
701da177e4SLinus Torvalds gda_t *gdap = GDA;
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds nodes_clear(node_online_map);
73*0c445078SMike Rapoport (Microsoft) nodes_clear(node_possible_map);
74c80b4896SThomas Bogendoerfer for (i = 0; i < MAX_NUMNODES; i++) {
751da177e4SLinus Torvalds nasid_t nasid = gdap->g_nasidtable[i];
761da177e4SLinus Torvalds if (nasid == INVALID_NASID)
771da177e4SLinus Torvalds break;
784bf841ebSThomas Bogendoerfer node_set_online(nasid);
79*0c445078SMike Rapoport (Microsoft) node_set(nasid, node_possible_map);
80d6972bb4SThomas Bogendoerfer highest = node_scan_cpus(nasid, highest);
811da177e4SLinus Torvalds }
821da177e4SLinus Torvalds
831da177e4SLinus Torvalds printk("Discovered %d cpus on %d nodes\n", highest + 1, num_online_nodes());
841da177e4SLinus Torvalds }
851da177e4SLinus Torvalds
intr_clear_all(nasid_t nasid)8639408c6aSRalf Baechle static __init void intr_clear_all(nasid_t nasid)
871da177e4SLinus Torvalds {
881da177e4SLinus Torvalds int i;
891da177e4SLinus Torvalds
901da177e4SLinus Torvalds REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0);
911da177e4SLinus Torvalds REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0);
921da177e4SLinus Torvalds REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0);
931da177e4SLinus Torvalds REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0);
9439408c6aSRalf Baechle
9539408c6aSRalf Baechle for (i = 0; i < 128; i++)
9639408c6aSRalf Baechle REMOTE_HUB_CLR_INTR(nasid, i);
971da177e4SLinus Torvalds }
981da177e4SLinus Torvalds
ip27_send_ipi_single(int destid,unsigned int action)9987353d8aSRalf Baechle static void ip27_send_ipi_single(int destid, unsigned int action)
1001da177e4SLinus Torvalds {
1011da177e4SLinus Torvalds int irq;
1021da177e4SLinus Torvalds
1031da177e4SLinus Torvalds switch (action) {
1041da177e4SLinus Torvalds case SMP_RESCHEDULE_YOURSELF:
1051da177e4SLinus Torvalds irq = CPU_RESCHED_A_IRQ;
1061da177e4SLinus Torvalds break;
1071da177e4SLinus Torvalds case SMP_CALL_FUNCTION:
1081da177e4SLinus Torvalds irq = CPU_CALL_A_IRQ;
1091da177e4SLinus Torvalds break;
1101da177e4SLinus Torvalds default:
1111da177e4SLinus Torvalds panic("sendintr");
1121da177e4SLinus Torvalds }
1131da177e4SLinus Torvalds
1141da177e4SLinus Torvalds irq += cputoslice(destid);
1151da177e4SLinus Torvalds
1161da177e4SLinus Torvalds /*
1174bf841ebSThomas Bogendoerfer * Set the interrupt bit associated with the CPU we want to
1184bf841ebSThomas Bogendoerfer * send the interrupt to.
1191da177e4SLinus Torvalds */
1204bf841ebSThomas Bogendoerfer REMOTE_HUB_SEND_INTR(cpu_to_node(destid), irq);
1211da177e4SLinus Torvalds }
12287353d8aSRalf Baechle
ip27_send_ipi_mask(const struct cpumask * mask,unsigned int action)123b533e652SRalf Baechle static void ip27_send_ipi_mask(const struct cpumask *mask, unsigned int action)
12487353d8aSRalf Baechle {
12587353d8aSRalf Baechle unsigned int i;
12687353d8aSRalf Baechle
12748a048feSRusty Russell for_each_cpu(i, mask)
12887353d8aSRalf Baechle ip27_send_ipi_single(i, action);
12987353d8aSRalf Baechle }
13087353d8aSRalf Baechle
ip27_init_cpu(void)1312c865620SThomas Bogendoerfer static void ip27_init_cpu(void)
13287353d8aSRalf Baechle {
13387353d8aSRalf Baechle per_cpu_init();
13487353d8aSRalf Baechle }
13587353d8aSRalf Baechle
ip27_smp_finish(void)136078a55fcSPaul Gortmaker static void ip27_smp_finish(void)
13787353d8aSRalf Baechle {
138b32bb803SThomas Bogendoerfer hub_rt_clock_event_init();
139b32bb803SThomas Bogendoerfer local_irq_enable();
14087353d8aSRalf Baechle }
14187353d8aSRalf Baechle
14287353d8aSRalf Baechle /*
14387353d8aSRalf Baechle * Launch a slave into smp_bootstrap(). It doesn't take an argument, and we
14487353d8aSRalf Baechle * set sp to the kernel stack of the newly created idle process, gp to the proc
14587353d8aSRalf Baechle * struct so that current_thread_info() will work.
14687353d8aSRalf Baechle */
ip27_boot_secondary(int cpu,struct task_struct * idle)147d595d423SPaul Burton static int ip27_boot_secondary(int cpu, struct task_struct *idle)
14887353d8aSRalf Baechle {
14987353d8aSRalf Baechle unsigned long gp = (unsigned long)task_thread_info(idle);
15087353d8aSRalf Baechle unsigned long sp = __KSTK_TOS(idle);
15187353d8aSRalf Baechle
15287353d8aSRalf Baechle LAUNCH_SLAVE(cputonasid(cpu), cputoslice(cpu),
15387353d8aSRalf Baechle (launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap),
15487353d8aSRalf Baechle 0, (void *) sp, (void *) gp);
155d595d423SPaul Burton return 0;
15687353d8aSRalf Baechle }
15787353d8aSRalf Baechle
ip27_smp_setup(void)15887353d8aSRalf Baechle static void __init ip27_smp_setup(void)
15987353d8aSRalf Baechle {
1604bf841ebSThomas Bogendoerfer nasid_t nasid;
16187353d8aSRalf Baechle
1624bf841ebSThomas Bogendoerfer for_each_online_node(nasid) {
1634bf841ebSThomas Bogendoerfer if (nasid == 0)
16487353d8aSRalf Baechle continue;
1654bf841ebSThomas Bogendoerfer intr_clear_all(nasid);
16687353d8aSRalf Baechle }
16787353d8aSRalf Baechle
16887353d8aSRalf Baechle replicate_kernel_text();
16987353d8aSRalf Baechle
17087353d8aSRalf Baechle /*
1714bf841ebSThomas Bogendoerfer * PROM sets up system, that boot cpu is always first CPU on nasid 0
17287353d8aSRalf Baechle */
173d6972bb4SThomas Bogendoerfer cputonasid(0) = 0;
174d6972bb4SThomas Bogendoerfer cputoslice(0) = LOCAL_HUB_L(PI_CPU_NUM);
17587353d8aSRalf Baechle }
17687353d8aSRalf Baechle
ip27_prepare_cpus(unsigned int max_cpus)17787353d8aSRalf Baechle static void __init ip27_prepare_cpus(unsigned int max_cpus)
17887353d8aSRalf Baechle {
17987353d8aSRalf Baechle /* We already did everything necessary earlier */
18087353d8aSRalf Baechle }
18187353d8aSRalf Baechle
182ff2c8252SMatt Redfearn const struct plat_smp_ops ip27_smp_ops = {
18387353d8aSRalf Baechle .send_ipi_single = ip27_send_ipi_single,
18487353d8aSRalf Baechle .send_ipi_mask = ip27_send_ipi_mask,
1852c865620SThomas Bogendoerfer .init_secondary = ip27_init_cpu,
18687353d8aSRalf Baechle .smp_finish = ip27_smp_finish,
18787353d8aSRalf Baechle .boot_secondary = ip27_boot_secondary,
18887353d8aSRalf Baechle .smp_setup = ip27_smp_setup,
18987353d8aSRalf Baechle .prepare_cpus = ip27_prepare_cpus,
1902c865620SThomas Bogendoerfer .prepare_boot_cpu = ip27_init_cpu,
19187353d8aSRalf Baechle };
192