| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * SMP support for BPA machines. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef DEBUG
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/kernel.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>
 | 
					
						
							| 
									
										
										
										
											2011-12-21 16:26:03 -08:00
										 |  |  | #include <linux/device.h>
 | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | #include <linux/cpu.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <asm/ptrace.h>
 | 
					
						
							| 
									
										
										
										
											2011-07-26 16:09:06 -07:00
										 |  |  | #include <linux/atomic.h>
 | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | #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>
 | 
					
						
							|  |  |  | #include <asm/firmware.h>
 | 
					
						
							|  |  |  | #include <asm/rtas.h>
 | 
					
						
							| 
									
										
										
										
											2007-10-25 15:27:44 +10:00
										 |  |  | #include <asm/cputhreads.h>
 | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "interrupt.h"
 | 
					
						
							| 
									
										
										
										
											2007-10-30 06:24:19 +11:00
										 |  |  | #include <asm/udbg.h>
 | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  | #define DBG(fmt...) udbg_printf(fmt)
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define DBG(fmt...)
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											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-10-31 20:08:38 -05: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 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-12-21 14:04:10 -08:00
										 |  |  | static inline int smp_startup_cpu(unsigned int lcpu) | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | { | 
					
						
							|  |  |  | 	int status; | 
					
						
							|  |  |  | 	unsigned long start_here = __pa((u32)*((unsigned long *) | 
					
						
							| 
									
										
										
										
											2006-08-11 00:07:08 -05:00
										 |  |  | 					       generic_secondary_smp_init)); | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | 	unsigned int pcpu; | 
					
						
							|  |  |  | 	int start_cpu; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-28 05:07:23 +00:00
										 |  |  | 	if (cpumask_test_cpu(lcpu, &of_spin_map)) | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | 		/* 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-10-31 20:08:38 -05: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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu); | 
					
						
							|  |  |  | 	if (status != 0) { | 
					
						
							|  |  |  | 		printk(KERN_ERR "start-cpu failed: %i\n", status); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int __init smp_iic_probe(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	iic_request_IPIs(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-28 05:07:23 +00:00
										 |  |  | 	return cpumask_weight(cpu_possible_mask); | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 14:04:10 -08:00
										 |  |  | static void smp_cell_setup_cpu(int cpu) | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (cpu != boot_cpuid) | 
					
						
							|  |  |  | 		iic_setup_cpu(); | 
					
						
							| 
									
										
										
										
											2008-11-28 09:51:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * change default DABRX to allow user watchpoints | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER); | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 14:04:10 -08:00
										 |  |  | static int smp_cell_kick_cpu(int nr) | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | { | 
					
						
							|  |  |  | 	BUG_ON(nr < 0 || nr >= NR_CPUS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!smp_startup_cpu(nr)) | 
					
						
							| 
									
										
										
										
											2011-04-11 21:46:19 +00:00
										 |  |  | 		return -ENOENT; | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * 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; | 
					
						
							| 
									
										
										
										
											2011-04-11 21:46:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct smp_ops_t bpa_iic_smp_ops = { | 
					
						
							| 
									
										
										
										
											2011-05-24 20:34:18 +00:00
										 |  |  | 	.message_pass	= iic_message_pass, | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | 	.probe		= smp_iic_probe, | 
					
						
							|  |  |  | 	.kick_cpu	= smp_cell_kick_cpu, | 
					
						
							| 
									
										
										
										
											2008-11-28 09:51:24 +00:00
										 |  |  | 	.setup_cpu	= smp_cell_setup_cpu, | 
					
						
							| 
									
										
										
										
											2013-08-05 14:58:35 -05:00
										 |  |  | 	.cpu_bootable	= smp_generic_cpu_bootable, | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* This is called very early */ | 
					
						
							|  |  |  | void __init smp_init_cell(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DBG(" -> smp_init_cell()\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	smp_ops = &bpa_iic_smp_ops; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Mark threads which are still spinning in hold loops. */ | 
					
						
							|  |  |  | 	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) | 
					
						
							| 
									
										
										
										
											2011-04-28 05:07:23 +00:00
										 |  |  | 				cpumask_set_cpu(i, &of_spin_map); | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-04-28 05:07:23 +00:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		cpumask_copy(&of_spin_map, cpu_present_mask); | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-28 05:07:23 +00:00
										 |  |  | 	cpumask_clear_cpu(boot_cpuid, &of_spin_map); | 
					
						
							| 
									
										
										
										
											2005-10-31 20:08:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* 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-10-31 20:08:38 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DBG(" <- smp_init_cell()\n"); | 
					
						
							|  |  |  | } |