Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 1 | /* |
| 2 | * SMP support for BPA machines. |
| 3 | * |
| 4 | * Dave Engebretsen, Peter Bergner, and |
| 5 | * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com |
| 6 | * |
| 7 | * Plus various changes from other IBM teams... |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version |
| 12 | * 2 of the License, or (at your option) any later version. |
| 13 | */ |
| 14 | |
| 15 | #undef DEBUG |
| 16 | |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 17 | #include <linux/kernel.h> |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 18 | #include <linux/sched.h> |
| 19 | #include <linux/smp.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/spinlock.h> |
| 24 | #include <linux/cache.h> |
| 25 | #include <linux/err.h> |
Kay Sievers | edbaa60 | 2011-12-21 16:26:03 -0800 | [diff] [blame] | 26 | #include <linux/device.h> |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 27 | #include <linux/cpu.h> |
| 28 | |
| 29 | #include <asm/ptrace.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 30 | #include <linux/atomic.h> |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 31 | #include <asm/irq.h> |
| 32 | #include <asm/page.h> |
| 33 | #include <asm/pgtable.h> |
| 34 | #include <asm/io.h> |
| 35 | #include <asm/prom.h> |
| 36 | #include <asm/smp.h> |
| 37 | #include <asm/paca.h> |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 38 | #include <asm/machdep.h> |
| 39 | #include <asm/cputable.h> |
| 40 | #include <asm/firmware.h> |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 41 | #include <asm/rtas.h> |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 42 | #include <asm/cputhreads.h> |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 43 | |
| 44 | #include "interrupt.h" |
will schmidt | aa39be0 | 2007-10-30 06:24:19 +1100 | [diff] [blame] | 45 | #include <asm/udbg.h> |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 46 | |
| 47 | #ifdef DEBUG |
| 48 | #define DBG(fmt...) udbg_printf(fmt) |
| 49 | #else |
| 50 | #define DBG(fmt...) |
| 51 | #endif |
| 52 | |
| 53 | /* |
Milton Miller | 6a75a6b | 2008-10-20 15:37:03 +0000 | [diff] [blame] | 54 | * The Primary thread of each non-boot processor was started from the OF client |
| 55 | * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop. |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 56 | */ |
| 57 | static cpumask_t of_spin_map; |
| 58 | |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 59 | /** |
| 60 | * smp_startup_cpu() - start the given cpu |
| 61 | * |
| 62 | * At boot time, there is nothing to do for primary threads which were |
| 63 | * started from Open Firmware. For anything else, call RTAS with the |
| 64 | * appropriate start location. |
| 65 | * |
| 66 | * Returns: |
| 67 | * 0 - failure |
| 68 | * 1 - success |
| 69 | */ |
Greg Kroah-Hartman | cad5cef | 2012-12-21 14:04:10 -0800 | [diff] [blame] | 70 | static inline int smp_startup_cpu(unsigned int lcpu) |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 71 | { |
| 72 | int status; |
| 73 | unsigned long start_here = __pa((u32)*((unsigned long *) |
Olof Johansson | f39b7a5 | 2006-08-11 00:07:08 -0500 | [diff] [blame] | 74 | generic_secondary_smp_init)); |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 75 | unsigned int pcpu; |
| 76 | int start_cpu; |
| 77 | |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 78 | if (cpumask_test_cpu(lcpu, &of_spin_map)) |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 79 | /* Already started by OF and sitting in spin loop */ |
| 80 | return 1; |
| 81 | |
| 82 | pcpu = get_hard_smp_processor_id(lcpu); |
| 83 | |
| 84 | /* Fixup atomic count: it exited inside IRQ handler. */ |
Al Viro | b5e2fc1 | 2006-01-12 01:06:01 -0800 | [diff] [blame] | 85 | task_thread_info(paca[lcpu].__current)->preempt_count = 0; |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * If the RTAS start-cpu token does not exist then presume the |
| 89 | * cpu is already spinning. |
| 90 | */ |
| 91 | start_cpu = rtas_token("start-cpu"); |
| 92 | if (start_cpu == RTAS_UNKNOWN_SERVICE) |
| 93 | return 1; |
| 94 | |
| 95 | status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu); |
| 96 | if (status != 0) { |
| 97 | printk(KERN_ERR "start-cpu failed: %i\n", status); |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | return 1; |
| 102 | } |
| 103 | |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 104 | static int __init smp_iic_probe(void) |
| 105 | { |
| 106 | iic_request_IPIs(); |
| 107 | |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 108 | return cpumask_weight(cpu_possible_mask); |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 109 | } |
| 110 | |
Greg Kroah-Hartman | cad5cef | 2012-12-21 14:04:10 -0800 | [diff] [blame] | 111 | static void smp_cell_setup_cpu(int cpu) |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 112 | { |
| 113 | if (cpu != boot_cpuid) |
| 114 | iic_setup_cpu(); |
Arnd Bergmann | 960cedb | 2008-11-28 09:51:24 +0000 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * change default DABRX to allow user watchpoints |
| 118 | */ |
| 119 | mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER); |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 120 | } |
| 121 | |
Greg Kroah-Hartman | cad5cef | 2012-12-21 14:04:10 -0800 | [diff] [blame] | 122 | static int smp_cell_kick_cpu(int nr) |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 123 | { |
| 124 | BUG_ON(nr < 0 || nr >= NR_CPUS); |
| 125 | |
| 126 | if (!smp_startup_cpu(nr)) |
Michael Ellerman | de30097 | 2011-04-11 21:46:19 +0000 | [diff] [blame] | 127 | return -ENOENT; |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 128 | |
| 129 | /* |
| 130 | * The processor is currently spinning, waiting for the |
| 131 | * cpu_start field to become non-zero After we set cpu_start, |
| 132 | * the processor will continue on to secondary_start |
| 133 | */ |
| 134 | paca[nr].cpu_start = 1; |
Michael Ellerman | de30097 | 2011-04-11 21:46:19 +0000 | [diff] [blame] | 135 | |
| 136 | return 0; |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 137 | } |
| 138 | |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 139 | static struct smp_ops_t bpa_iic_smp_ops = { |
Milton Miller | d5a1c19 | 2011-05-24 20:34:18 +0000 | [diff] [blame] | 140 | .message_pass = iic_message_pass, |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 141 | .probe = smp_iic_probe, |
| 142 | .kick_cpu = smp_cell_kick_cpu, |
Arnd Bergmann | 960cedb | 2008-11-28 09:51:24 +0000 | [diff] [blame] | 143 | .setup_cpu = smp_cell_setup_cpu, |
Andy Fleming | 39fd402 | 2013-08-05 14:58:35 -0500 | [diff] [blame] | 144 | .cpu_bootable = smp_generic_cpu_bootable, |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | /* This is called very early */ |
| 148 | void __init smp_init_cell(void) |
| 149 | { |
| 150 | int i; |
| 151 | |
| 152 | DBG(" -> smp_init_cell()\n"); |
| 153 | |
| 154 | smp_ops = &bpa_iic_smp_ops; |
| 155 | |
| 156 | /* Mark threads which are still spinning in hold loops. */ |
| 157 | if (cpu_has_feature(CPU_FTR_SMT)) { |
| 158 | for_each_present_cpu(i) { |
Milton Miller | 6a75a6b | 2008-10-20 15:37:03 +0000 | [diff] [blame] | 159 | if (cpu_thread_in_core(i) == 0) |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 160 | cpumask_set_cpu(i, &of_spin_map); |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 161 | } |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 162 | } else |
| 163 | cpumask_copy(&of_spin_map, cpu_present_mask); |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 164 | |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 165 | cpumask_clear_cpu(boot_cpuid, &of_spin_map); |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 166 | |
| 167 | /* Non-lpar has additional take/give timebase */ |
| 168 | if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) { |
Benjamin Herrenschmidt | c4007a2 | 2009-06-16 16:42:50 +0000 | [diff] [blame] | 169 | smp_ops->give_timebase = rtas_give_timebase; |
| 170 | smp_ops->take_timebase = rtas_take_timebase; |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | DBG(" <- smp_init_cell()\n"); |
| 174 | } |