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);
73c80b4896SThomas Bogendoerfer for (i = 0; i < MAX_NUMNODES; i++) {
741da177e4SLinus Torvalds nasid_t nasid = gdap->g_nasidtable[i];
751da177e4SLinus Torvalds if (nasid == INVALID_NASID)
761da177e4SLinus Torvalds break;
774bf841ebSThomas Bogendoerfer node_set_online(nasid);
78d6972bb4SThomas Bogendoerfer highest = node_scan_cpus(nasid, highest);
791da177e4SLinus Torvalds }
801da177e4SLinus Torvalds
811da177e4SLinus Torvalds printk("Discovered %d cpus on %d nodes\n", highest + 1, num_online_nodes());
821da177e4SLinus Torvalds }
831da177e4SLinus Torvalds
intr_clear_all(nasid_t nasid)8439408c6aSRalf Baechle static __init void intr_clear_all(nasid_t nasid)
851da177e4SLinus Torvalds {
861da177e4SLinus Torvalds int i;
871da177e4SLinus Torvalds
881da177e4SLinus Torvalds REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0);
891da177e4SLinus Torvalds REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0);
901da177e4SLinus Torvalds REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0);
911da177e4SLinus Torvalds REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0);
9239408c6aSRalf Baechle
9339408c6aSRalf Baechle for (i = 0; i < 128; i++)
9439408c6aSRalf Baechle REMOTE_HUB_CLR_INTR(nasid, i);
951da177e4SLinus Torvalds }
961da177e4SLinus Torvalds
ip27_send_ipi_single(int destid,unsigned int action)9787353d8aSRalf Baechle static void ip27_send_ipi_single(int destid, unsigned int action)
981da177e4SLinus Torvalds {
991da177e4SLinus Torvalds int irq;
1001da177e4SLinus Torvalds
1011da177e4SLinus Torvalds switch (action) {
1021da177e4SLinus Torvalds case SMP_RESCHEDULE_YOURSELF:
1031da177e4SLinus Torvalds irq = CPU_RESCHED_A_IRQ;
1041da177e4SLinus Torvalds break;
1051da177e4SLinus Torvalds case SMP_CALL_FUNCTION:
1061da177e4SLinus Torvalds irq = CPU_CALL_A_IRQ;
1071da177e4SLinus Torvalds break;
1081da177e4SLinus Torvalds default:
1091da177e4SLinus Torvalds panic("sendintr");
1101da177e4SLinus Torvalds }
1111da177e4SLinus Torvalds
1121da177e4SLinus Torvalds irq += cputoslice(destid);
1131da177e4SLinus Torvalds
1141da177e4SLinus Torvalds /*
1154bf841ebSThomas Bogendoerfer * Set the interrupt bit associated with the CPU we want to
1164bf841ebSThomas Bogendoerfer * send the interrupt to.
1171da177e4SLinus Torvalds */
1184bf841ebSThomas Bogendoerfer REMOTE_HUB_SEND_INTR(cpu_to_node(destid), irq);
1191da177e4SLinus Torvalds }
12087353d8aSRalf Baechle
ip27_send_ipi_mask(const struct cpumask * mask,unsigned int action)121b533e652SRalf Baechle static void ip27_send_ipi_mask(const struct cpumask *mask, unsigned int action)
12287353d8aSRalf Baechle {
12387353d8aSRalf Baechle unsigned int i;
12487353d8aSRalf Baechle
12548a048feSRusty Russell for_each_cpu(i, mask)
12687353d8aSRalf Baechle ip27_send_ipi_single(i, action);
12787353d8aSRalf Baechle }
12887353d8aSRalf Baechle
ip27_init_cpu(void)1292c865620SThomas Bogendoerfer static void ip27_init_cpu(void)
13087353d8aSRalf Baechle {
13187353d8aSRalf Baechle per_cpu_init();
13287353d8aSRalf Baechle }
13387353d8aSRalf Baechle
ip27_smp_finish(void)134078a55fcSPaul Gortmaker static void ip27_smp_finish(void)
13587353d8aSRalf Baechle {
136b32bb803SThomas Bogendoerfer hub_rt_clock_event_init();
137b32bb803SThomas Bogendoerfer local_irq_enable();
13887353d8aSRalf Baechle }
13987353d8aSRalf Baechle
14087353d8aSRalf Baechle /*
14187353d8aSRalf Baechle * Launch a slave into smp_bootstrap(). It doesn't take an argument, and we
14287353d8aSRalf Baechle * set sp to the kernel stack of the newly created idle process, gp to the proc
14387353d8aSRalf Baechle * struct so that current_thread_info() will work.
14487353d8aSRalf Baechle */
ip27_boot_secondary(int cpu,struct task_struct * idle)145d595d423SPaul Burton static int ip27_boot_secondary(int cpu, struct task_struct *idle)
14687353d8aSRalf Baechle {
14787353d8aSRalf Baechle unsigned long gp = (unsigned long)task_thread_info(idle);
14887353d8aSRalf Baechle unsigned long sp = __KSTK_TOS(idle);
14987353d8aSRalf Baechle
15087353d8aSRalf Baechle LAUNCH_SLAVE(cputonasid(cpu), cputoslice(cpu),
15187353d8aSRalf Baechle (launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap),
15287353d8aSRalf Baechle 0, (void *) sp, (void *) gp);
153d595d423SPaul Burton return 0;
15487353d8aSRalf Baechle }
15587353d8aSRalf Baechle
ip27_smp_setup(void)15687353d8aSRalf Baechle static void __init ip27_smp_setup(void)
15787353d8aSRalf Baechle {
1584bf841ebSThomas Bogendoerfer nasid_t nasid;
15987353d8aSRalf Baechle
1604bf841ebSThomas Bogendoerfer for_each_online_node(nasid) {
1614bf841ebSThomas Bogendoerfer if (nasid == 0)
16287353d8aSRalf Baechle continue;
1634bf841ebSThomas Bogendoerfer intr_clear_all(nasid);
16487353d8aSRalf Baechle }
16587353d8aSRalf Baechle
16687353d8aSRalf Baechle replicate_kernel_text();
16787353d8aSRalf Baechle
16887353d8aSRalf Baechle /*
1694bf841ebSThomas Bogendoerfer * PROM sets up system, that boot cpu is always first CPU on nasid 0
17087353d8aSRalf Baechle */
171d6972bb4SThomas Bogendoerfer cputonasid(0) = 0;
172d6972bb4SThomas Bogendoerfer cputoslice(0) = LOCAL_HUB_L(PI_CPU_NUM);
17387353d8aSRalf Baechle }
17487353d8aSRalf Baechle
ip27_prepare_cpus(unsigned int max_cpus)17587353d8aSRalf Baechle static void __init ip27_prepare_cpus(unsigned int max_cpus)
17687353d8aSRalf Baechle {
17787353d8aSRalf Baechle /* We already did everything necessary earlier */
17887353d8aSRalf Baechle }
17987353d8aSRalf Baechle
180ff2c8252SMatt Redfearn const struct plat_smp_ops ip27_smp_ops = {
18187353d8aSRalf Baechle .send_ipi_single = ip27_send_ipi_single,
18287353d8aSRalf Baechle .send_ipi_mask = ip27_send_ipi_mask,
1832c865620SThomas Bogendoerfer .init_secondary = ip27_init_cpu,
18487353d8aSRalf Baechle .smp_finish = ip27_smp_finish,
18587353d8aSRalf Baechle .boot_secondary = ip27_boot_secondary,
18687353d8aSRalf Baechle .smp_setup = ip27_smp_setup,
18787353d8aSRalf Baechle .prepare_cpus = ip27_prepare_cpus,
1882c865620SThomas Bogendoerfer .prepare_boot_cpu = ip27_init_cpu,
18987353d8aSRalf Baechle };
190