xref: /openbmc/linux/arch/parisc/kernel/smp.c (revision d3b3c637)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds ** SMP Support
41da177e4SLinus Torvalds **
51da177e4SLinus Torvalds ** Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
61da177e4SLinus Torvalds ** Copyright (C) 1999 David Mosberger-Tang <davidm@hpl.hp.com>
71da177e4SLinus Torvalds ** Copyright (C) 2001,2004 Grant Grundler <grundler@parisc-linux.org>
81da177e4SLinus Torvalds **
91da177e4SLinus Torvalds ** Lots of stuff stolen from arch/alpha/kernel/smp.c
101da177e4SLinus Torvalds ** ...and then parisc stole from arch/ia64/kernel/smp.c. Thanks David! :^)
111da177e4SLinus Torvalds **
121da177e4SLinus Torvalds ** Thanks to John Curry and Ullas Ponnadi. I learned a lot from their work.
131da177e4SLinus Torvalds ** -grant (1/12/2001)
141da177e4SLinus Torvalds **
151da177e4SLinus Torvalds */
161da177e4SLinus Torvalds #include <linux/types.h>
171da177e4SLinus Torvalds #include <linux/spinlock.h>
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds #include <linux/kernel.h>
201da177e4SLinus Torvalds #include <linux/module.h>
2168e21be2SIngo Molnar #include <linux/sched/mm.h>
221da177e4SLinus Torvalds #include <linux/init.h>
231da177e4SLinus Torvalds #include <linux/interrupt.h>
241da177e4SLinus Torvalds #include <linux/smp.h>
251da177e4SLinus Torvalds #include <linux/kernel_stat.h>
261da177e4SLinus Torvalds #include <linux/mm.h>
274e950f6fSAlexey Dobriyan #include <linux/err.h>
281da177e4SLinus Torvalds #include <linux/delay.h>
291da177e4SLinus Torvalds #include <linux/bitops.h>
30d75f054aSHelge Deller #include <linux/ftrace.h>
31ec2e0f98SSrivatsa S. Bhat #include <linux/cpu.h>
3266e29fcdSSven Schnelle #include <linux/kgdb.h>
3388b3aac6SHelge Deller #include <linux/sched/hotplug.h>
341da177e4SLinus Torvalds 
3560063497SArun Sharma #include <linux/atomic.h>
361da177e4SLinus Torvalds #include <asm/current.h>
371da177e4SLinus Torvalds #include <asm/delay.h>
381b2425e3SMatthew Wilcox #include <asm/tlbflush.h>
391da177e4SLinus Torvalds 
401da177e4SLinus Torvalds #include <asm/io.h>
411da177e4SLinus Torvalds #include <asm/irq.h>		/* for CPU_IRQ_REGION and friends */
421da177e4SLinus Torvalds #include <asm/mmu_context.h>
431da177e4SLinus Torvalds #include <asm/page.h>
441da177e4SLinus Torvalds #include <asm/processor.h>
451da177e4SLinus Torvalds #include <asm/ptrace.h>
461da177e4SLinus Torvalds #include <asm/unistd.h>
471da177e4SLinus Torvalds #include <asm/cacheflush.h>
481da177e4SLinus Torvalds 
495492a0f0SKyle McMartin #undef DEBUG_SMP
505492a0f0SKyle McMartin #ifdef DEBUG_SMP
515492a0f0SKyle McMartin static int smp_debug_lvl = 0;
525492a0f0SKyle McMartin #define smp_debug(lvl, printargs...)		\
535492a0f0SKyle McMartin 		if (lvl >= smp_debug_lvl)	\
545492a0f0SKyle McMartin 			printk(printargs);
555492a0f0SKyle McMartin #else
56ef017bebSHelge Deller #define smp_debug(lvl, ...)	do { } while(0)
575492a0f0SKyle McMartin #endif /* DEBUG_SMP */
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds volatile struct task_struct *smp_init_current_idle_task;
601da177e4SLinus Torvalds 
61ef017bebSHelge Deller /* track which CPU is booting */
6260ffef06SPaul Gortmaker static volatile int cpu_now_booting;
631da177e4SLinus Torvalds 
646ad6c424SThomas Gleixner static DEFINE_PER_CPU(spinlock_t, ipi_lock);
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds enum ipi_message_type {
671da177e4SLinus Torvalds 	IPI_NOP=0,
681da177e4SLinus Torvalds 	IPI_RESCHEDULE=1,
691da177e4SLinus Torvalds 	IPI_CALL_FUNC,
701da177e4SLinus Torvalds 	IPI_CPU_START,
711da177e4SLinus Torvalds 	IPI_CPU_STOP,
7266e29fcdSSven Schnelle 	IPI_CPU_TEST,
7366e29fcdSSven Schnelle #ifdef CONFIG_KGDB
7466e29fcdSSven Schnelle 	IPI_ENTER_KGDB,
7566e29fcdSSven Schnelle #endif
761da177e4SLinus Torvalds };
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds 
791da177e4SLinus Torvalds /********** SMP inter processor interrupt and communication routines */
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds #undef PER_CPU_IRQ_REGION
821da177e4SLinus Torvalds #ifdef PER_CPU_IRQ_REGION
831da177e4SLinus Torvalds /* XXX REVISIT Ignore for now.
841da177e4SLinus Torvalds **    *May* need this "hook" to register IPI handler
851da177e4SLinus Torvalds **    once we have perCPU ExtIntr switch tables.
861da177e4SLinus Torvalds */
871da177e4SLinus Torvalds static void
ipi_init(int cpuid)881da177e4SLinus Torvalds ipi_init(int cpuid)
891da177e4SLinus Torvalds {
901da177e4SLinus Torvalds #error verify IRQ_OFFSET(IPI_IRQ) is ipi_interrupt() in new IRQ region
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds 	if(cpu_online(cpuid) )
931da177e4SLinus Torvalds 	{
941da177e4SLinus Torvalds 		switch_to_idle_task(current);
951da177e4SLinus Torvalds 	}
961da177e4SLinus Torvalds 
971da177e4SLinus Torvalds 	return;
981da177e4SLinus Torvalds }
991da177e4SLinus Torvalds #endif
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds /*
1031da177e4SLinus Torvalds ** Yoink this CPU from the runnable list...
1041da177e4SLinus Torvalds **
1051da177e4SLinus Torvalds */
1061da177e4SLinus Torvalds static void
halt_processor(void)1071da177e4SLinus Torvalds halt_processor(void)
1081da177e4SLinus Torvalds {
1091da177e4SLinus Torvalds 	/* REVISIT : redirect I/O Interrupts to another CPU? */
1101da177e4SLinus Torvalds 	/* REVISIT : does PM *know* this CPU isn't available? */
1119bc181d8SRusty Russell 	set_cpu_online(smp_processor_id(), false);
1121da177e4SLinus Torvalds 	local_irq_disable();
113507efd63SSven Schnelle 	__pdc_cpu_rendezvous();
1141da177e4SLinus Torvalds 	for (;;)
1151da177e4SLinus Torvalds 		;
1161da177e4SLinus Torvalds }
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds 
119d75f054aSHelge Deller irqreturn_t __irq_entry
ipi_interrupt(int irq,void * dev_id)120c7753f18SMatthew Wilcox ipi_interrupt(int irq, void *dev_id)
1211da177e4SLinus Torvalds {
1221da177e4SLinus Torvalds 	int this_cpu = smp_processor_id();
123ef017bebSHelge Deller 	struct cpuinfo_parisc *p = &per_cpu(cpu_data, this_cpu);
1241da177e4SLinus Torvalds 	unsigned long ops;
1251da177e4SLinus Torvalds 	unsigned long flags;
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds 	for (;;) {
1283c97b5e9SKyle McMartin 		spinlock_t *lock = &per_cpu(ipi_lock, this_cpu);
1293c97b5e9SKyle McMartin 		spin_lock_irqsave(lock, flags);
1301da177e4SLinus Torvalds 		ops = p->pending_ipi;
1311da177e4SLinus Torvalds 		p->pending_ipi = 0;
1323c97b5e9SKyle McMartin 		spin_unlock_irqrestore(lock, flags);
1331da177e4SLinus Torvalds 
1341da177e4SLinus Torvalds 		mb(); /* Order bit clearing and data access. */
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds 		if (!ops)
1371da177e4SLinus Torvalds 		    break;
1381da177e4SLinus Torvalds 
1391da177e4SLinus Torvalds 		while (ops) {
1401da177e4SLinus Torvalds 			unsigned long which = ffz(~ops);
1411da177e4SLinus Torvalds 
142d911aed8SJames Bottomley 			ops &= ~(1 << which);
143d911aed8SJames Bottomley 
1441da177e4SLinus Torvalds 			switch (which) {
145d911aed8SJames Bottomley 			case IPI_NOP:
1465492a0f0SKyle McMartin 				smp_debug(100, KERN_DEBUG "CPU%d IPI_NOP\n", this_cpu);
147d911aed8SJames Bottomley 				break;
148d911aed8SJames Bottomley 
1491da177e4SLinus Torvalds 			case IPI_RESCHEDULE:
1505492a0f0SKyle McMartin 				smp_debug(100, KERN_DEBUG "CPU%d IPI_RESCHEDULE\n", this_cpu);
151cd85d551SHelge Deller 				inc_irq_stat(irq_resched_count);
152184748ccSPeter Zijlstra 				scheduler_ipi();
1531da177e4SLinus Torvalds 				break;
1541da177e4SLinus Torvalds 
1551da177e4SLinus Torvalds 			case IPI_CALL_FUNC:
1565492a0f0SKyle McMartin 				smp_debug(100, KERN_DEBUG "CPU%d IPI_CALL_FUNC\n", this_cpu);
157b102f29bSHelge Deller 				inc_irq_stat(irq_call_count);
158dbcf4787SJens Axboe 				generic_smp_call_function_interrupt();
159dbcf4787SJens Axboe 				break;
1601da177e4SLinus Torvalds 
1611da177e4SLinus Torvalds 			case IPI_CPU_START:
1625492a0f0SKyle McMartin 				smp_debug(100, KERN_DEBUG "CPU%d IPI_CPU_START\n", this_cpu);
1631da177e4SLinus Torvalds 				break;
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds 			case IPI_CPU_STOP:
1665492a0f0SKyle McMartin 				smp_debug(100, KERN_DEBUG "CPU%d IPI_CPU_STOP\n", this_cpu);
1671da177e4SLinus Torvalds 				halt_processor();
1681da177e4SLinus Torvalds 				break;
1691da177e4SLinus Torvalds 
1701da177e4SLinus Torvalds 			case IPI_CPU_TEST:
1715492a0f0SKyle McMartin 				smp_debug(100, KERN_DEBUG "CPU%d is alive!\n", this_cpu);
1721da177e4SLinus Torvalds 				break;
17366e29fcdSSven Schnelle #ifdef CONFIG_KGDB
17466e29fcdSSven Schnelle 			case IPI_ENTER_KGDB:
17566e29fcdSSven Schnelle 				smp_debug(100, KERN_DEBUG "CPU%d ENTER_KGDB\n", this_cpu);
17666e29fcdSSven Schnelle 				kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
17766e29fcdSSven Schnelle 				break;
17866e29fcdSSven Schnelle #endif
1791da177e4SLinus Torvalds 			default:
1801da177e4SLinus Torvalds 				printk(KERN_CRIT "Unknown IPI num on CPU%d: %lu\n",
1811da177e4SLinus Torvalds 					this_cpu, which);
1821da177e4SLinus Torvalds 				return IRQ_NONE;
1831da177e4SLinus Torvalds 			} /* Switch */
184f4d0d40cSHelge Deller 
185f4d0d40cSHelge Deller 			/* before doing more, let in any pending interrupts */
186f4d0d40cSHelge Deller 			if (ops) {
1877085689eSJames Bottomley 				local_irq_enable();
1887085689eSJames Bottomley 				local_irq_disable();
189f4d0d40cSHelge Deller 			}
1901da177e4SLinus Torvalds 		} /* while (ops) */
1911da177e4SLinus Torvalds 	}
1921da177e4SLinus Torvalds 	return IRQ_HANDLED;
1931da177e4SLinus Torvalds }
1941da177e4SLinus Torvalds 
1951da177e4SLinus Torvalds 
1961da177e4SLinus Torvalds static inline void
ipi_send(int cpu,enum ipi_message_type op)1971da177e4SLinus Torvalds ipi_send(int cpu, enum ipi_message_type op)
1981da177e4SLinus Torvalds {
199ef017bebSHelge Deller 	struct cpuinfo_parisc *p = &per_cpu(cpu_data, cpu);
2003c97b5e9SKyle McMartin 	spinlock_t *lock = &per_cpu(ipi_lock, cpu);
2011da177e4SLinus Torvalds 	unsigned long flags;
2021da177e4SLinus Torvalds 
2033c97b5e9SKyle McMartin 	spin_lock_irqsave(lock, flags);
2041da177e4SLinus Torvalds 	p->pending_ipi |= 1 << op;
205ef017bebSHelge Deller 	gsc_writel(IPI_IRQ - CPU_IRQ_BASE, p->hpa);
2063c97b5e9SKyle McMartin 	spin_unlock_irqrestore(lock, flags);
2071da177e4SLinus Torvalds }
2081da177e4SLinus Torvalds 
209dbcf4787SJens Axboe static void
send_IPI_mask(const struct cpumask * mask,enum ipi_message_type op)21091887a36SRusty Russell send_IPI_mask(const struct cpumask *mask, enum ipi_message_type op)
211dbcf4787SJens Axboe {
212dbcf4787SJens Axboe 	int cpu;
213dbcf4787SJens Axboe 
21491887a36SRusty Russell 	for_each_cpu(cpu, mask)
215dbcf4787SJens Axboe 		ipi_send(cpu, op);
216dbcf4787SJens Axboe }
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds static inline void
send_IPI_single(int dest_cpu,enum ipi_message_type op)2191da177e4SLinus Torvalds send_IPI_single(int dest_cpu, enum ipi_message_type op)
2201da177e4SLinus Torvalds {
2217f2347a4SHelge Deller 	BUG_ON(dest_cpu == NO_PROC_ID);
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds 	ipi_send(dest_cpu, op);
2241da177e4SLinus Torvalds }
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds static inline void
send_IPI_allbutself(enum ipi_message_type op)2271da177e4SLinus Torvalds send_IPI_allbutself(enum ipi_message_type op)
2281da177e4SLinus Torvalds {
2291da177e4SLinus Torvalds 	int i;
2301da177e4SLinus Torvalds 
2311c2fb946SSven Schnelle 	preempt_disable();
232394e3902SAndrew Morton 	for_each_online_cpu(i) {
233394e3902SAndrew Morton 		if (i != smp_processor_id())
2341da177e4SLinus Torvalds 			send_IPI_single(i, op);
2351da177e4SLinus Torvalds 	}
2361c2fb946SSven Schnelle 	preempt_enable();
2371da177e4SLinus Torvalds }
2381da177e4SLinus Torvalds 
23966e29fcdSSven Schnelle #ifdef CONFIG_KGDB
kgdb_roundup_cpus(void)24066e29fcdSSven Schnelle void kgdb_roundup_cpus(void)
24166e29fcdSSven Schnelle {
24266e29fcdSSven Schnelle 	send_IPI_allbutself(IPI_ENTER_KGDB);
24366e29fcdSSven Schnelle }
24466e29fcdSSven Schnelle #endif
2451da177e4SLinus Torvalds 
2461da177e4SLinus Torvalds inline void
smp_send_stop(void)2471da177e4SLinus Torvalds smp_send_stop(void)	{ send_IPI_allbutself(IPI_CPU_STOP); }
2481da177e4SLinus Torvalds 
2491da177e4SLinus Torvalds void
arch_smp_send_reschedule(int cpu)2504c8c3c7fSValentin Schneider arch_smp_send_reschedule(int cpu) { send_IPI_single(cpu, IPI_RESCHEDULE); }
2511da177e4SLinus Torvalds 
252d911aed8SJames Bottomley void
smp_send_all_nop(void)253d911aed8SJames Bottomley smp_send_all_nop(void)
254d911aed8SJames Bottomley {
255d911aed8SJames Bottomley 	send_IPI_allbutself(IPI_NOP);
256d911aed8SJames Bottomley }
257d911aed8SJames Bottomley 
arch_send_call_function_ipi_mask(const struct cpumask * mask)25891887a36SRusty Russell void arch_send_call_function_ipi_mask(const struct cpumask *mask)
2591da177e4SLinus Torvalds {
260dbcf4787SJens Axboe 	send_IPI_mask(mask, IPI_CALL_FUNC);
2611da177e4SLinus Torvalds }
2621da177e4SLinus Torvalds 
arch_send_call_function_single_ipi(int cpu)263dbcf4787SJens Axboe void arch_send_call_function_single_ipi(int cpu)
264dbcf4787SJens Axboe {
265528d8eb2SJiang Liu 	send_IPI_single(cpu, IPI_CALL_FUNC);
2661da177e4SLinus Torvalds }
2671da177e4SLinus Torvalds 
2681da177e4SLinus Torvalds /*
2691da177e4SLinus Torvalds  * Called by secondaries to update state and initialize CPU registers.
2701da177e4SLinus Torvalds  */
27188b3aac6SHelge Deller static void
smp_cpu_init(int cpunum)2721da177e4SLinus Torvalds smp_cpu_init(int cpunum)
2731da177e4SLinus Torvalds {
2741da177e4SLinus Torvalds 	/* Set modes and Enable floating point coprocessor */
275a7e6601fSHelge Deller 	init_per_cpu(cpunum);
2761da177e4SLinus Torvalds 
2771da177e4SLinus Torvalds 	disable_sr_hashing();
2781da177e4SLinus Torvalds 
2791da177e4SLinus Torvalds 	mb();
2801da177e4SLinus Torvalds 
2811da177e4SLinus Torvalds 	/* Well, support 2.4 linux scheme as well. */
2827ec6118cSRusty Russell 	if (cpu_online(cpunum))	{
2831da177e4SLinus Torvalds 		extern void machine_halt(void); /* arch/parisc.../process.c */
2841da177e4SLinus Torvalds 
2851da177e4SLinus Torvalds 		printk(KERN_CRIT "CPU#%d already initialized!\n", cpunum);
2861da177e4SLinus Torvalds 		machine_halt();
2871da177e4SLinus Torvalds 	}
288ec2e0f98SSrivatsa S. Bhat 
289ec2e0f98SSrivatsa S. Bhat 	notify_cpu_starting(cpunum);
290ec2e0f98SSrivatsa S. Bhat 
2919bc181d8SRusty Russell 	set_cpu_online(cpunum, true);
2921da177e4SLinus Torvalds 
2931da177e4SLinus Torvalds 	/* Initialise the idle task for this CPU */
294f1f10076SVegard Nossum 	mmgrab(&init_mm);
2951da177e4SLinus Torvalds 	current->active_mm = &init_mm;
2967f2347a4SHelge Deller 	BUG_ON(current->mm);
2971da177e4SLinus Torvalds 	enter_lazy_tlb(&init_mm, current);
2981da177e4SLinus Torvalds 
2997022672eSSimon Arlott 	init_IRQ();   /* make sure no IRQs are enabled or pending */
30056f335c8SGrant Grundler 	start_cpu_itimer();
3011da177e4SLinus Torvalds }
3021da177e4SLinus Torvalds 
3031da177e4SLinus Torvalds 
3041da177e4SLinus Torvalds /*
3051da177e4SLinus Torvalds  * Slaves start using C here. Indirectly called from smp_slave_stext.
3061da177e4SLinus Torvalds  * Do what start_kernel() and main() do for boot strap processor (aka monarch)
3071da177e4SLinus Torvalds  */
smp_callin(unsigned long pdce_proc)30888b3aac6SHelge Deller void smp_callin(unsigned long pdce_proc)
3091da177e4SLinus Torvalds {
3101da177e4SLinus Torvalds 	int slave_id = cpu_now_booting;
3111da177e4SLinus Torvalds 
3120ed1fe4aSHelge Deller #ifdef CONFIG_64BIT
3130ed1fe4aSHelge Deller 	WARN_ON(((unsigned long)(PAGE0->mem_pdc_hi) << 32
3140ed1fe4aSHelge Deller 			| PAGE0->mem_pdc) != pdce_proc);
3150ed1fe4aSHelge Deller #endif
3160ed1fe4aSHelge Deller 
3171da177e4SLinus Torvalds 	smp_cpu_init(slave_id);
3181da177e4SLinus Torvalds 
3191da177e4SLinus Torvalds 	flush_cache_all_local(); /* start with known state */
3201b2425e3SMatthew Wilcox 	flush_tlb_all_local(NULL);
3211da177e4SLinus Torvalds 
3221da177e4SLinus Torvalds 	local_irq_enable();  /* Interrupts have been off until now */
3231da177e4SLinus Torvalds 
324fc6d73d6SThomas Gleixner 	cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds 	/* NOTREACHED */
3271da177e4SLinus Torvalds 	panic("smp_callin() AAAAaaaaahhhh....\n");
3281da177e4SLinus Torvalds }
3291da177e4SLinus Torvalds 
3301da177e4SLinus Torvalds /*
3311da177e4SLinus Torvalds  * Bring one cpu online.
3321da177e4SLinus Torvalds  */
smp_boot_one_cpu(int cpuid,struct task_struct * idle)33388b3aac6SHelge Deller static int smp_boot_one_cpu(int cpuid, struct task_struct *idle)
3341da177e4SLinus Torvalds {
335ef017bebSHelge Deller 	const struct cpuinfo_parisc *p = &per_cpu(cpu_data, cpuid);
3361da177e4SLinus Torvalds 	long timeout;
3371da177e4SLinus Torvalds 
33888b3aac6SHelge Deller #ifdef CONFIG_HOTPLUG_CPU
33988b3aac6SHelge Deller 	int i;
34088b3aac6SHelge Deller 
34188b3aac6SHelge Deller 	/* reset irq statistics for this CPU */
34288b3aac6SHelge Deller 	memset(&per_cpu(irq_stat, cpuid), 0, sizeof(irq_cpustat_t));
34388b3aac6SHelge Deller 	for (i = 0; i < NR_IRQS; i++) {
34488b3aac6SHelge Deller 		struct irq_desc *desc = irq_to_desc(i);
34588b3aac6SHelge Deller 
34688b3aac6SHelge Deller 		if (desc && desc->kstat_irqs)
34788b3aac6SHelge Deller 			*per_cpu_ptr(desc->kstat_irqs, cpuid) = 0;
34888b3aac6SHelge Deller 	}
34988b3aac6SHelge Deller #endif
35088b3aac6SHelge Deller 
35188b3aac6SHelge Deller 	/* wait until last booting CPU has started. */
35288b3aac6SHelge Deller 	while (cpu_now_booting)
35388b3aac6SHelge Deller 		;
35488b3aac6SHelge Deller 
3551da177e4SLinus Torvalds 	/* Let _start know what logical CPU we're booting
3561da177e4SLinus Torvalds 	** (offset into init_tasks[],cpu_data[])
3571da177e4SLinus Torvalds 	*/
3581da177e4SLinus Torvalds 	cpu_now_booting = cpuid;
3591da177e4SLinus Torvalds 
3601da177e4SLinus Torvalds 	/*
3611da177e4SLinus Torvalds 	** boot strap code needs to know the task address since
3621da177e4SLinus Torvalds 	** it also contains the process stack.
3631da177e4SLinus Torvalds 	*/
3641da177e4SLinus Torvalds 	smp_init_current_idle_task = idle ;
3651da177e4SLinus Torvalds 	mb();
3661da177e4SLinus Torvalds 
367ef017bebSHelge Deller 	printk(KERN_INFO "Releasing cpu %d now, hpa=%lx\n", cpuid, p->hpa);
3681da177e4SLinus Torvalds 
3691da177e4SLinus Torvalds 	/*
3701da177e4SLinus Torvalds 	** This gets PDC to release the CPU from a very tight loop.
3711da177e4SLinus Torvalds 	**
3721da177e4SLinus Torvalds 	** From the PA-RISC 2.0 Firmware Architecture Reference Specification:
3731da177e4SLinus Torvalds 	** "The MEM_RENDEZ vector specifies the location of OS_RENDEZ which
3741da177e4SLinus Torvalds 	** is executed after receiving the rendezvous signal (an interrupt to
3751da177e4SLinus Torvalds 	** EIR{0}). MEM_RENDEZ is valid only when it is nonzero and the
3761da177e4SLinus Torvalds 	** contents of memory are valid."
3771da177e4SLinus Torvalds 	*/
378ef017bebSHelge Deller 	gsc_writel(TIMER_IRQ - CPU_IRQ_BASE, p->hpa);
3791da177e4SLinus Torvalds 	mb();
3801da177e4SLinus Torvalds 
3811da177e4SLinus Torvalds 	/*
3821da177e4SLinus Torvalds 	 * OK, wait a bit for that CPU to finish staggering about.
3831da177e4SLinus Torvalds 	 * Slave will set a bit when it reaches smp_cpu_init().
3841da177e4SLinus Torvalds 	 * Once the "monarch CPU" sees the bit change, it can move on.
3851da177e4SLinus Torvalds 	 */
3861da177e4SLinus Torvalds 	for (timeout = 0; timeout < 10000; timeout++) {
3871da177e4SLinus Torvalds 		if(cpu_online(cpuid)) {
3881da177e4SLinus Torvalds 			/* Which implies Slave has started up */
3891da177e4SLinus Torvalds 			cpu_now_booting = 0;
3901da177e4SLinus Torvalds 			goto alive ;
3911da177e4SLinus Torvalds 		}
3921da177e4SLinus Torvalds 		udelay(100);
3931da177e4SLinus Torvalds 		barrier();
3941da177e4SLinus Torvalds 	}
3951da177e4SLinus Torvalds 	printk(KERN_CRIT "SMP: CPU:%d is stuck.\n", cpuid);
3961da177e4SLinus Torvalds 	return -1;
3971da177e4SLinus Torvalds 
3981da177e4SLinus Torvalds alive:
3991da177e4SLinus Torvalds 	/* Remember the Slave data */
4005492a0f0SKyle McMartin 	smp_debug(100, KERN_DEBUG "SMP: CPU:%d came alive after %ld _us\n",
4011da177e4SLinus Torvalds 		cpuid, timeout * 100);
4021da177e4SLinus Torvalds 	return 0;
4031da177e4SLinus Torvalds }
4041da177e4SLinus Torvalds 
smp_prepare_boot_cpu(void)405ef017bebSHelge Deller void __init smp_prepare_boot_cpu(void)
4061da177e4SLinus Torvalds {
407ef017bebSHelge Deller 	int bootstrap_processor = per_cpu(cpu_data, 0).cpuid;
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds 	/* Setup BSP mappings */
410ef017bebSHelge Deller 	printk(KERN_INFO "SMP: bootstrap CPU ID is %d\n", bootstrap_processor);
4111da177e4SLinus Torvalds 
4129bc181d8SRusty Russell 	set_cpu_online(bootstrap_processor, true);
4139bc181d8SRusty Russell 	set_cpu_present(bootstrap_processor, true);
4141da177e4SLinus Torvalds }
4151da177e4SLinus Torvalds 
4161da177e4SLinus Torvalds 
4171da177e4SLinus Torvalds 
4181da177e4SLinus Torvalds /*
4191da177e4SLinus Torvalds ** inventory.c:do_inventory() hasn't yet been run and thus we
4207022672eSSimon Arlott ** don't 'discover' the additional CPUs until later.
4211da177e4SLinus Torvalds */
smp_prepare_cpus(unsigned int max_cpus)4221da177e4SLinus Torvalds void __init smp_prepare_cpus(unsigned int max_cpus)
4231da177e4SLinus Torvalds {
4246ad6c424SThomas Gleixner 	int cpu;
4256ad6c424SThomas Gleixner 
4266ad6c424SThomas Gleixner 	for_each_possible_cpu(cpu)
4276ad6c424SThomas Gleixner 		spin_lock_init(&per_cpu(ipi_lock, cpu));
4286ad6c424SThomas Gleixner 
4299bc181d8SRusty Russell 	init_cpu_present(cpumask_of(0));
4301da177e4SLinus Torvalds }
4311da177e4SLinus Torvalds 
4321da177e4SLinus Torvalds 
smp_cpus_done(unsigned int cpu_max)43388b3aac6SHelge Deller void __init smp_cpus_done(unsigned int cpu_max)
4341da177e4SLinus Torvalds {
4351da177e4SLinus Torvalds }
4361da177e4SLinus Torvalds 
4371da177e4SLinus Torvalds 
__cpu_up(unsigned int cpu,struct task_struct * tidle)43860ffef06SPaul Gortmaker int __cpu_up(unsigned int cpu, struct task_struct *tidle)
4391da177e4SLinus Torvalds {
44088b3aac6SHelge Deller 	if (cpu_online(cpu))
44188b3aac6SHelge Deller 		return 0;
4421da177e4SLinus Torvalds 
443*d3b3c637SHelge Deller 	if (num_online_cpus() < nr_cpu_ids &&
444*d3b3c637SHelge Deller 		num_online_cpus() < setup_max_cpus &&
445*d3b3c637SHelge Deller 		smp_boot_one_cpu(cpu, tidle))
44688b3aac6SHelge Deller 		return -EIO;
44788b3aac6SHelge Deller 
44888b3aac6SHelge Deller 	return cpu_online(cpu) ? 0 : -EIO;
44988b3aac6SHelge Deller }
45088b3aac6SHelge Deller 
45188b3aac6SHelge Deller /*
45288b3aac6SHelge Deller  * __cpu_disable runs on the processor to be shutdown.
45388b3aac6SHelge Deller  */
__cpu_disable(void)45488b3aac6SHelge Deller int __cpu_disable(void)
45588b3aac6SHelge Deller {
45688b3aac6SHelge Deller #ifdef CONFIG_HOTPLUG_CPU
45788b3aac6SHelge Deller 	unsigned int cpu = smp_processor_id();
45888b3aac6SHelge Deller 
45988b3aac6SHelge Deller 	remove_cpu_topology(cpu);
46088b3aac6SHelge Deller 
46188b3aac6SHelge Deller 	/*
46288b3aac6SHelge Deller 	 * Take this CPU offline.  Once we clear this, we can't return,
46388b3aac6SHelge Deller 	 * and we must not schedule until we're ready to give up the cpu.
46488b3aac6SHelge Deller 	 */
46588b3aac6SHelge Deller 	set_cpu_online(cpu, false);
46688b3aac6SHelge Deller 
4671afde47dSHelge Deller 	/* Find a new timesync master */
4681afde47dSHelge Deller 	if (cpu == time_keeper_id) {
4691afde47dSHelge Deller 		time_keeper_id = cpumask_first(cpu_online_mask);
4701afde47dSHelge Deller 		pr_info("CPU %d is now promoted to time-keeper master\n", time_keeper_id);
4711afde47dSHelge Deller 	}
4721afde47dSHelge Deller 
47388b3aac6SHelge Deller 	disable_percpu_irq(IPI_IRQ);
47488b3aac6SHelge Deller 
47588b3aac6SHelge Deller 	irq_migrate_all_off_this_cpu();
47688b3aac6SHelge Deller 
47788b3aac6SHelge Deller 	flush_cache_all_local();
47888b3aac6SHelge Deller 	flush_tlb_all_local(NULL);
47988b3aac6SHelge Deller 
48088b3aac6SHelge Deller 	/* disable all irqs, including timer irq */
48188b3aac6SHelge Deller 	local_irq_disable();
48288b3aac6SHelge Deller 
48388b3aac6SHelge Deller 	/* wait for next timer irq ... */
48488b3aac6SHelge Deller 	mdelay(1000/HZ+100);
48588b3aac6SHelge Deller 
48688b3aac6SHelge Deller 	/* ... and then clear all pending external irqs */
48788b3aac6SHelge Deller 	set_eiem(0);
48888b3aac6SHelge Deller 	mtctl(~0UL, CR_EIRR);
48988b3aac6SHelge Deller 	mfctl(CR_EIRR);
49088b3aac6SHelge Deller 	mtctl(0, CR_EIRR);
49188b3aac6SHelge Deller #endif
49288b3aac6SHelge Deller 	return 0;
49388b3aac6SHelge Deller }
49488b3aac6SHelge Deller 
49588b3aac6SHelge Deller /*
49688b3aac6SHelge Deller  * called on the thread which is asking for a CPU to be shutdown -
49788b3aac6SHelge Deller  * waits until shutdown has completed, or it is timed out.
49888b3aac6SHelge Deller  */
__cpu_die(unsigned int cpu)49988b3aac6SHelge Deller void __cpu_die(unsigned int cpu)
50088b3aac6SHelge Deller {
50188b3aac6SHelge Deller 	pdc_cpu_rendezvous_lock();
50288b3aac6SHelge Deller }
50351e0efe1SThomas Gleixner 
arch_cpuhp_cleanup_dead_cpu(unsigned int cpu)50451e0efe1SThomas Gleixner void arch_cpuhp_cleanup_dead_cpu(unsigned int cpu)
50551e0efe1SThomas Gleixner {
50688b3aac6SHelge Deller 	pr_info("CPU%u: is shutting down\n", cpu);
50788b3aac6SHelge Deller 
50888b3aac6SHelge Deller 	/* set task's state to interruptible sleep */
50988b3aac6SHelge Deller 	set_current_state(TASK_INTERRUPTIBLE);
51088b3aac6SHelge Deller 	schedule_timeout((IS_ENABLED(CONFIG_64BIT) ? 8:2) * HZ);
51188b3aac6SHelge Deller 
51288b3aac6SHelge Deller 	pdc_cpu_rendezvous_unlock();
5131da177e4SLinus Torvalds }
514