| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-10-10 22:03:41 +10:00
										 |  |  |  * SMP support for pSeries machines. | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Dave Engebretsen, Peter Bergner, and | 
					
						
							|  |  |  |  * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Plus various changes from other IBM teams... | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *      This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  *      modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  *      as published by the Free Software Foundation; either version | 
					
						
							|  |  |  |  *      2 of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/kernel.h>
 | 
					
						
							|  |  |  | #include <linux/module.h>
 | 
					
						
							|  |  |  | #include <linux/sched.h>
 | 
					
						
							|  |  |  | #include <linux/smp.h>
 | 
					
						
							|  |  |  | #include <linux/interrupt.h>
 | 
					
						
							|  |  |  | #include <linux/delay.h>
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							|  |  |  | #include <linux/spinlock.h>
 | 
					
						
							|  |  |  | #include <linux/cache.h>
 | 
					
						
							|  |  |  | #include <linux/err.h>
 | 
					
						
							|  |  |  | #include <linux/sysdev.h>
 | 
					
						
							|  |  |  | #include <linux/cpu.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <asm/ptrace.h>
 | 
					
						
							|  |  |  | #include <asm/atomic.h>
 | 
					
						
							|  |  |  | #include <asm/irq.h>
 | 
					
						
							|  |  |  | #include <asm/page.h>
 | 
					
						
							|  |  |  | #include <asm/pgtable.h>
 | 
					
						
							|  |  |  | #include <asm/io.h>
 | 
					
						
							|  |  |  | #include <asm/prom.h>
 | 
					
						
							|  |  |  | #include <asm/smp.h>
 | 
					
						
							|  |  |  | #include <asm/paca.h>
 | 
					
						
							|  |  |  | #include <asm/machdep.h>
 | 
					
						
							|  |  |  | #include <asm/cputable.h>
 | 
					
						
							| 
									
										
										
										
											2005-08-03 14:35:25 +10:00
										 |  |  | #include <asm/firmware.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <asm/system.h>
 | 
					
						
							|  |  |  | #include <asm/rtas.h>
 | 
					
						
							|  |  |  | #include <asm/pSeries_reconfig.h>
 | 
					
						
							| 
									
										
										
										
											2005-09-27 13:51:59 +10:00
										 |  |  | #include <asm/mpic.h>
 | 
					
						
							| 
									
										
										
										
											2005-11-11 23:04:40 +11:00
										 |  |  | #include <asm/vdso_datapage.h>
 | 
					
						
							| 
									
										
										
										
											2007-10-25 15:27:44 +10:00
										 |  |  | #include <asm/cputhreads.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-03 15:33:31 +11:00
										 |  |  | #include "plpar_wrappers.h"
 | 
					
						
							| 
									
										
										
										
											2007-02-08 18:33:55 +11:00
										 |  |  | #include "pseries.h"
 | 
					
						
							| 
									
										
										
										
											2008-10-10 01:56:29 +00:00
										 |  |  | #include "xics.h"
 | 
					
						
							| 
									
										
										
										
											2009-10-29 19:22:53 +00:00
										 |  |  | #include "offline_states.h"
 | 
					
						
							| 
									
										
										
										
											2005-11-03 15:33:31 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-10-20 15:37:03 +00:00
										 |  |  |  * The Primary thread of each non-boot processor was started from the OF client | 
					
						
							|  |  |  |  * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop. | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | static cpumask_t of_spin_map; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * smp_startup_cpu() - start the given cpu | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * At boot time, there is nothing to do for primary threads which were | 
					
						
							|  |  |  |  * started from Open Firmware.  For anything else, call RTAS with the | 
					
						
							|  |  |  |  * appropriate start location. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Returns: | 
					
						
							|  |  |  |  *	0	- failure | 
					
						
							|  |  |  |  *	1	- success | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static inline int __devinit smp_startup_cpu(unsigned int lcpu) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int status; | 
					
						
							|  |  |  | 	unsigned long start_here = __pa((u32)*((unsigned long *) | 
					
						
							| 
									
										
										
										
											2006-08-11 00:07:08 -05:00
										 |  |  | 					       generic_secondary_smp_init)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	unsigned int pcpu; | 
					
						
							| 
									
										
										
										
											2005-09-12 13:17:27 +10:00
										 |  |  | 	int start_cpu; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (cpu_isset(lcpu, of_spin_map)) | 
					
						
							|  |  |  | 		/* Already started by OF and sitting in spin loop */ | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pcpu = get_hard_smp_processor_id(lcpu); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Fixup atomic count: it exited inside IRQ handler. */ | 
					
						
							| 
									
										
										
										
											2006-01-12 01:06:01 -08:00
										 |  |  | 	task_thread_info(paca[lcpu].__current)->preempt_count	= 0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-29 19:22:53 +00:00
										 |  |  | 	if (get_cpu_current_state(lcpu) == CPU_STATE_INACTIVE) | 
					
						
							|  |  |  | 		goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-12 13:17:27 +10:00
										 |  |  | 	/* 
 | 
					
						
							|  |  |  | 	 * If the RTAS start-cpu token does not exist then presume the | 
					
						
							|  |  |  | 	 * cpu is already spinning. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	start_cpu = rtas_token("start-cpu"); | 
					
						
							|  |  |  | 	if (start_cpu == RTAS_UNKNOWN_SERVICE) | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-16 14:13:53 +11:00
										 |  |  | 	status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, pcpu); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (status != 0) { | 
					
						
							|  |  |  | 		printk(KERN_ERR "start-cpu failed: %i\n", status); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-09-12 13:17:27 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-29 19:22:53 +00:00
										 |  |  | out: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-23 09:43:43 +10:00
										 |  |  | #ifdef CONFIG_XICS
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | static void __devinit smp_xics_setup_cpu(int cpu) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (cpu != boot_cpuid) | 
					
						
							|  |  |  | 		xics_setup_cpu(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-03 14:35:25 +10:00
										 |  |  | 	if (firmware_has_feature(FW_FEATURE_SPLPAR)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		vpa_init(cpu); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cpu_clear(cpu, of_spin_map); | 
					
						
							| 
									
										
										
										
											2009-10-29 19:22:53 +00:00
										 |  |  | 	set_cpu_current_state(cpu, CPU_STATE_ONLINE); | 
					
						
							|  |  |  | 	set_default_offline_state(cpu); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-06-23 09:43:43 +10:00
										 |  |  | #endif /* CONFIG_XICS */
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void __devinit smp_pSeries_kick_cpu(int nr) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-29 19:22:53 +00:00
										 |  |  | 	long rc; | 
					
						
							|  |  |  | 	unsigned long hcpuid; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	BUG_ON(nr < 0 || nr >= NR_CPUS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!smp_startup_cpu(nr)) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * The processor is currently spinning, waiting for the | 
					
						
							|  |  |  | 	 * cpu_start field to become non-zero After we set cpu_start, | 
					
						
							|  |  |  | 	 * the processor will continue on to secondary_start | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	paca[nr].cpu_start = 1; | 
					
						
							| 
									
										
										
										
											2009-10-29 19:22:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	set_preferred_offline_state(nr, CPU_STATE_ONLINE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (get_cpu_current_state(nr) == CPU_STATE_INACTIVE) { | 
					
						
							|  |  |  | 		hcpuid = get_hard_smp_processor_id(nr); | 
					
						
							|  |  |  | 		rc = plpar_hcall_norets(H_PROD, hcpuid); | 
					
						
							|  |  |  | 		if (rc != H_SUCCESS) | 
					
						
							| 
									
										
										
										
											2010-01-31 10:02:03 +00:00
										 |  |  | 			printk(KERN_ERR "Error: Prod to wake up processor %d " | 
					
						
							|  |  |  | 						"Ret= %ld\n", nr, rc); | 
					
						
							| 
									
										
										
										
											2009-10-29 19:22:53 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int smp_pSeries_cpu_bootable(unsigned int nr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* Special case - we inhibit secondary thread startup
 | 
					
						
							| 
									
										
										
										
											2008-10-20 15:37:03 +00:00
										 |  |  | 	 * during boot if the user requests it. | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	if (system_state < SYSTEM_RUNNING && | 
					
						
							| 
									
										
										
										
											2005-06-20 21:43:15 +10:00
										 |  |  | 	    cpu_has_feature(CPU_FTR_SMT) && | 
					
						
							| 
									
										
										
										
											2007-10-25 15:27:44 +10:00
										 |  |  | 	    !smt_enabled_at_boot && cpu_thread_in_core(nr) != 0) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-06-23 09:43:43 +10:00
										 |  |  | #ifdef CONFIG_MPIC
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | static struct smp_ops_t pSeries_mpic_smp_ops = { | 
					
						
							|  |  |  | 	.message_pass	= smp_mpic_message_pass, | 
					
						
							|  |  |  | 	.probe		= smp_mpic_probe, | 
					
						
							|  |  |  | 	.kick_cpu	= smp_pSeries_kick_cpu, | 
					
						
							|  |  |  | 	.setup_cpu	= smp_mpic_setup_cpu, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2005-06-23 09:43:43 +10:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | #ifdef CONFIG_XICS
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | static struct smp_ops_t pSeries_xics_smp_ops = { | 
					
						
							|  |  |  | 	.message_pass	= smp_xics_message_pass, | 
					
						
							|  |  |  | 	.probe		= smp_xics_probe, | 
					
						
							|  |  |  | 	.kick_cpu	= smp_pSeries_kick_cpu, | 
					
						
							|  |  |  | 	.setup_cpu	= smp_xics_setup_cpu, | 
					
						
							|  |  |  | 	.cpu_bootable	= smp_pSeries_cpu_bootable, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2005-06-23 09:43:43 +10:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* This is called very early */ | 
					
						
							| 
									
										
										
										
											2006-07-03 21:36:01 +10:00
										 |  |  | static void __init smp_init_pseries(void) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 15:13:19 +10:00
										 |  |  | 	pr_debug(" -> smp_init_pSeries()\n"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Mark threads which are still spinning in hold loops. */ | 
					
						
							| 
									
										
										
										
											2005-06-20 21:43:15 +10:00
										 |  |  | 	if (cpu_has_feature(CPU_FTR_SMT)) { | 
					
						
							|  |  |  | 		for_each_present_cpu(i) {  | 
					
						
							| 
									
										
										
										
											2008-10-20 15:37:03 +00:00
										 |  |  | 			if (cpu_thread_in_core(i) == 0) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 				cpu_set(i, of_spin_map); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-06-20 21:43:15 +10:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		of_spin_map = cpu_present_map; | 
					
						
							| 
									
										
										
										
											2005-06-20 21:43:15 +10:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cpu_clear(boot_cpuid, of_spin_map); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Non-lpar has additional take/give timebase */ | 
					
						
							|  |  |  | 	if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) { | 
					
						
							| 
									
										
										
										
											2009-06-16 16:42:50 +00:00
										 |  |  | 		smp_ops->give_timebase = rtas_give_timebase; | 
					
						
							|  |  |  | 		smp_ops->take_timebase = rtas_take_timebase; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-24 15:13:19 +10:00
										 |  |  | 	pr_debug(" <- smp_init_pSeries()\n"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-03 21:36:01 +10:00
										 |  |  | #ifdef CONFIG_MPIC
 | 
					
						
							|  |  |  | void __init smp_init_pseries_mpic(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	smp_ops = &pSeries_mpic_smp_ops; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	smp_init_pseries(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void __init smp_init_pseries_xics(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	smp_ops = &pSeries_xics_smp_ops; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	smp_init_pseries(); | 
					
						
							|  |  |  | } |