xref: /linux/arch/mips/sgi-ip27/ip27-smp.c (revision b32bb803fb52cc669762780d44b4c3d9e3d799f6)
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>
111da177e4SLinus Torvalds #include <linux/nodemask.h>
121da177e4SLinus Torvalds #include <asm/page.h>
131da177e4SLinus Torvalds #include <asm/processor.h>
141da177e4SLinus Torvalds #include <asm/sn/arch.h>
151da177e4SLinus Torvalds #include <asm/sn/gda.h>
161da177e4SLinus Torvalds #include <asm/sn/intr.h>
171da177e4SLinus Torvalds #include <asm/sn/klconfig.h>
181da177e4SLinus Torvalds #include <asm/sn/launch.h>
191da177e4SLinus Torvalds #include <asm/sn/mapped_kernel.h>
201da177e4SLinus Torvalds #include <asm/sn/sn_private.h>
211da177e4SLinus Torvalds #include <asm/sn/types.h>
221da177e4SLinus Torvalds #include <asm/sn/sn0/hubpi.h>
231da177e4SLinus Torvalds #include <asm/sn/sn0/hubio.h>
241da177e4SLinus Torvalds #include <asm/sn/sn0/ip27.h>
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds /*
271da177e4SLinus Torvalds  * Takes as first input the PROM assigned cpu id, and the kernel
281da177e4SLinus Torvalds  * assigned cpu id as the second.
291da177e4SLinus Torvalds  */
301da177e4SLinus Torvalds static void alloc_cpupda(cpuid_t cpu, int cpunum)
311da177e4SLinus Torvalds {
321da177e4SLinus Torvalds 	cnodeid_t node = get_cpu_cnode(cpu);
331da177e4SLinus Torvalds 	nasid_t nasid = COMPACT_TO_NASID_NODEID(node);
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds 	cputonasid(cpunum) = nasid;
36cc6e8e08SRalf Baechle 	sn_cpu_info[cpunum].p_nodeid = node;
371da177e4SLinus Torvalds 	cputoslice(cpunum) = get_cpu_slice(cpu);
381da177e4SLinus Torvalds }
391da177e4SLinus Torvalds 
401da177e4SLinus Torvalds static nasid_t get_actual_nasid(lboard_t *brd)
411da177e4SLinus Torvalds {
421da177e4SLinus Torvalds 	klhub_t *hub;
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds 	if (!brd)
451da177e4SLinus Torvalds 		return INVALID_NASID;
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds 	/* find out if we are a completely disabled brd. */
481da177e4SLinus Torvalds 	hub  = (klhub_t *)find_first_component(brd, KLSTRUCT_HUB);
491da177e4SLinus Torvalds 	if (!hub)
501da177e4SLinus Torvalds 		return INVALID_NASID;
511da177e4SLinus Torvalds 	if (!(hub->hub_info.flags & KLINFO_ENABLE))	/* disabled node brd */
521da177e4SLinus Torvalds 		return hub->hub_info.physid;
531da177e4SLinus Torvalds 	else
541da177e4SLinus Torvalds 		return brd->brd_nasid;
551da177e4SLinus Torvalds }
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds static int do_cpumask(cnodeid_t cnode, nasid_t nasid, int highest)
581da177e4SLinus Torvalds {
591da177e4SLinus Torvalds 	static int tot_cpus_found = 0;
601da177e4SLinus Torvalds 	lboard_t *brd;
611da177e4SLinus Torvalds 	klcpu_t *acpu;
621da177e4SLinus Torvalds 	int cpus_found = 0;
631da177e4SLinus Torvalds 	cpuid_t cpuid;
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds 	brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27);
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds 	do {
681da177e4SLinus Torvalds 		acpu = (klcpu_t *)find_first_component(brd, KLSTRUCT_CPU);
691da177e4SLinus Torvalds 		while (acpu) {
701da177e4SLinus Torvalds 			cpuid = acpu->cpu_info.virtid;
711da177e4SLinus Torvalds 			/* cnode is not valid for completely disabled brds */
721da177e4SLinus Torvalds 			if (get_actual_nasid(brd) == brd->brd_nasid)
731da177e4SLinus Torvalds 				cpuid_to_compact_node[cpuid] = cnode;
741da177e4SLinus Torvalds 			if (cpuid > highest)
751da177e4SLinus Torvalds 				highest = cpuid;
761da177e4SLinus Torvalds 			/* Only let it join in if it's marked enabled */
771da177e4SLinus Torvalds 			if ((acpu->cpu_info.flags & KLINFO_ENABLE) &&
781da177e4SLinus Torvalds 			    (tot_cpus_found != NR_CPUS)) {
791da177e4SLinus Torvalds 				cpu_set(cpuid, phys_cpu_present_map);
801da177e4SLinus Torvalds 				alloc_cpupda(cpuid, tot_cpus_found);
811da177e4SLinus Torvalds 				cpus_found++;
821da177e4SLinus Torvalds 				tot_cpus_found++;
831da177e4SLinus Torvalds 			}
841da177e4SLinus Torvalds 			acpu = (klcpu_t *)find_component(brd, (klinfo_t *)acpu,
851da177e4SLinus Torvalds 								KLSTRUCT_CPU);
861da177e4SLinus Torvalds 		}
871da177e4SLinus Torvalds 		brd = KLCF_NEXT(brd);
881da177e4SLinus Torvalds 		if (!brd)
891da177e4SLinus Torvalds 			break;
901da177e4SLinus Torvalds 
911da177e4SLinus Torvalds 		brd = find_lboard(brd, KLTYPE_IP27);
921da177e4SLinus Torvalds 	} while (brd);
931da177e4SLinus Torvalds 
941da177e4SLinus Torvalds 	return highest;
951da177e4SLinus Torvalds }
961da177e4SLinus Torvalds 
971da177e4SLinus Torvalds void cpu_node_probe(void)
981da177e4SLinus Torvalds {
991da177e4SLinus Torvalds 	int i, highest = 0;
1001da177e4SLinus Torvalds 	gda_t *gdap = GDA;
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds 	/*
1031da177e4SLinus Torvalds 	 * Initialize the arrays to invalid nodeid (-1)
1041da177e4SLinus Torvalds 	 */
1051da177e4SLinus Torvalds 	for (i = 0; i < MAX_COMPACT_NODES; i++)
1061da177e4SLinus Torvalds 		compact_to_nasid_node[i] = INVALID_NASID;
1071da177e4SLinus Torvalds 	for (i = 0; i < MAX_NASIDS; i++)
1081da177e4SLinus Torvalds 		nasid_to_compact_node[i] = INVALID_CNODEID;
1091da177e4SLinus Torvalds 	for (i = 0; i < MAXCPUS; i++)
1101da177e4SLinus Torvalds 		cpuid_to_compact_node[i] = INVALID_CNODEID;
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds 	/*
1131da177e4SLinus Torvalds 	 * MCD - this whole "compact node" stuff can probably be dropped,
1141da177e4SLinus Torvalds 	 * as we can handle sparse numbering now
1151da177e4SLinus Torvalds 	 */
1161da177e4SLinus Torvalds 	nodes_clear(node_online_map);
1171da177e4SLinus Torvalds 	for (i = 0; i < MAX_COMPACT_NODES; i++) {
1181da177e4SLinus Torvalds 		nasid_t nasid = gdap->g_nasidtable[i];
1191da177e4SLinus Torvalds 		if (nasid == INVALID_NASID)
1201da177e4SLinus Torvalds 			break;
1211da177e4SLinus Torvalds 		compact_to_nasid_node[i] = nasid;
1221da177e4SLinus Torvalds 		nasid_to_compact_node[nasid] = i;
1231da177e4SLinus Torvalds 		node_set_online(num_online_nodes());
1241da177e4SLinus Torvalds 		highest = do_cpumask(i, nasid, highest);
1251da177e4SLinus Torvalds 	}
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds 	printk("Discovered %d cpus on %d nodes\n", highest + 1, num_online_nodes());
1281da177e4SLinus Torvalds }
1291da177e4SLinus Torvalds 
13039408c6aSRalf Baechle static __init void intr_clear_all(nasid_t nasid)
1311da177e4SLinus Torvalds {
1321da177e4SLinus Torvalds 	int i;
1331da177e4SLinus Torvalds 
1341da177e4SLinus Torvalds 	REMOTE_HUB_S(nasid, PI_INT_MASK0_A, 0);
1351da177e4SLinus Torvalds 	REMOTE_HUB_S(nasid, PI_INT_MASK0_B, 0);
1361da177e4SLinus Torvalds 	REMOTE_HUB_S(nasid, PI_INT_MASK1_A, 0);
1371da177e4SLinus Torvalds 	REMOTE_HUB_S(nasid, PI_INT_MASK1_B, 0);
13839408c6aSRalf Baechle 
13939408c6aSRalf Baechle 	for (i = 0; i < 128; i++)
14039408c6aSRalf Baechle 		REMOTE_HUB_CLR_INTR(nasid, i);
1411da177e4SLinus Torvalds }
1421da177e4SLinus Torvalds 
14387353d8aSRalf Baechle static void ip27_send_ipi_single(int destid, unsigned int action)
1441da177e4SLinus Torvalds {
1451da177e4SLinus Torvalds 	int irq;
1461da177e4SLinus Torvalds 
1471da177e4SLinus Torvalds 	switch (action) {
1481da177e4SLinus Torvalds 	case SMP_RESCHEDULE_YOURSELF:
1491da177e4SLinus Torvalds 		irq = CPU_RESCHED_A_IRQ;
1501da177e4SLinus Torvalds 		break;
1511da177e4SLinus Torvalds 	case SMP_CALL_FUNCTION:
1521da177e4SLinus Torvalds 		irq = CPU_CALL_A_IRQ;
1531da177e4SLinus Torvalds 		break;
1541da177e4SLinus Torvalds 	default:
1551da177e4SLinus Torvalds 		panic("sendintr");
1561da177e4SLinus Torvalds 	}
1571da177e4SLinus Torvalds 
1581da177e4SLinus Torvalds 	irq += cputoslice(destid);
1591da177e4SLinus Torvalds 
1601da177e4SLinus Torvalds 	/*
1611da177e4SLinus Torvalds 	 * Convert the compact hub number to the NASID to get the correct
1621da177e4SLinus Torvalds 	 * part of the address space.  Then set the interrupt bit associated
1631da177e4SLinus Torvalds 	 * with the CPU we want to send the interrupt to.
1641da177e4SLinus Torvalds 	 */
1651da177e4SLinus Torvalds 	REMOTE_HUB_SEND_INTR(COMPACT_TO_NASID_NODEID(cpu_to_node(destid)), irq);
1661da177e4SLinus Torvalds }
16787353d8aSRalf Baechle 
16887353d8aSRalf Baechle static void ip27_send_ipi_mask(cpumask_t mask, unsigned int action)
16987353d8aSRalf Baechle {
17087353d8aSRalf Baechle 	unsigned int i;
17187353d8aSRalf Baechle 
17287353d8aSRalf Baechle 	for_each_cpu_mask(i, mask)
17387353d8aSRalf Baechle 		ip27_send_ipi_single(i, action);
17487353d8aSRalf Baechle }
17587353d8aSRalf Baechle 
17687353d8aSRalf Baechle static void __cpuinit ip27_init_secondary(void)
17787353d8aSRalf Baechle {
17887353d8aSRalf Baechle 	per_cpu_init();
17987353d8aSRalf Baechle }
18087353d8aSRalf Baechle 
18187353d8aSRalf Baechle static void __cpuinit ip27_smp_finish(void)
18287353d8aSRalf Baechle {
183*b32bb803SThomas Bogendoerfer 	extern void hub_rt_clock_event_init(void);
184*b32bb803SThomas Bogendoerfer 
185*b32bb803SThomas Bogendoerfer 	hub_rt_clock_event_init();
186*b32bb803SThomas Bogendoerfer 	local_irq_enable();
18787353d8aSRalf Baechle }
18887353d8aSRalf Baechle 
18987353d8aSRalf Baechle static void __init ip27_cpus_done(void)
19087353d8aSRalf Baechle {
19187353d8aSRalf Baechle }
19287353d8aSRalf Baechle 
19387353d8aSRalf Baechle /*
19487353d8aSRalf Baechle  * Launch a slave into smp_bootstrap().  It doesn't take an argument, and we
19587353d8aSRalf Baechle  * set sp to the kernel stack of the newly created idle process, gp to the proc
19687353d8aSRalf Baechle  * struct so that current_thread_info() will work.
19787353d8aSRalf Baechle  */
19887353d8aSRalf Baechle static void __cpuinit ip27_boot_secondary(int cpu, struct task_struct *idle)
19987353d8aSRalf Baechle {
20087353d8aSRalf Baechle 	unsigned long gp = (unsigned long)task_thread_info(idle);
20187353d8aSRalf Baechle 	unsigned long sp = __KSTK_TOS(idle);
20287353d8aSRalf Baechle 
20387353d8aSRalf Baechle 	LAUNCH_SLAVE(cputonasid(cpu), cputoslice(cpu),
20487353d8aSRalf Baechle 		(launch_proc_t)MAPPED_KERN_RW_TO_K0(smp_bootstrap),
20587353d8aSRalf Baechle 		0, (void *) sp, (void *) gp);
20687353d8aSRalf Baechle }
20787353d8aSRalf Baechle 
20887353d8aSRalf Baechle static void __init ip27_smp_setup(void)
20987353d8aSRalf Baechle {
21087353d8aSRalf Baechle 	cnodeid_t	cnode;
21187353d8aSRalf Baechle 
21287353d8aSRalf Baechle 	for_each_online_node(cnode) {
21387353d8aSRalf Baechle 		if (cnode == 0)
21487353d8aSRalf Baechle 			continue;
21587353d8aSRalf Baechle 		intr_clear_all(COMPACT_TO_NASID_NODEID(cnode));
21687353d8aSRalf Baechle 	}
21787353d8aSRalf Baechle 
21887353d8aSRalf Baechle 	replicate_kernel_text();
21987353d8aSRalf Baechle 
22087353d8aSRalf Baechle 	/*
22187353d8aSRalf Baechle 	 * Assumption to be fixed: we're always booted on logical / physical
22287353d8aSRalf Baechle 	 * processor 0.  While we're always running on logical processor 0
22387353d8aSRalf Baechle 	 * this still means this is physical processor zero; it might for
22487353d8aSRalf Baechle 	 * example be disabled in the firwware.
22587353d8aSRalf Baechle 	 */
22687353d8aSRalf Baechle 	alloc_cpupda(0, 0);
22787353d8aSRalf Baechle }
22887353d8aSRalf Baechle 
22987353d8aSRalf Baechle static void __init ip27_prepare_cpus(unsigned int max_cpus)
23087353d8aSRalf Baechle {
23187353d8aSRalf Baechle 	/* We already did everything necessary earlier */
23287353d8aSRalf Baechle }
23387353d8aSRalf Baechle 
23487353d8aSRalf Baechle struct plat_smp_ops ip27_smp_ops = {
23587353d8aSRalf Baechle 	.send_ipi_single	= ip27_send_ipi_single,
23687353d8aSRalf Baechle 	.send_ipi_mask		= ip27_send_ipi_mask,
23787353d8aSRalf Baechle 	.init_secondary		= ip27_init_secondary,
23887353d8aSRalf Baechle 	.smp_finish		= ip27_smp_finish,
23987353d8aSRalf Baechle 	.cpus_done		= ip27_cpus_done,
24087353d8aSRalf Baechle 	.boot_secondary		= ip27_boot_secondary,
24187353d8aSRalf Baechle 	.smp_setup		= ip27_smp_setup,
24287353d8aSRalf Baechle 	.prepare_cpus		= ip27_prepare_cpus,
24387353d8aSRalf Baechle };
244