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> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/smp.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/spinlock.h> |
| 25 | #include <linux/cache.h> |
| 26 | #include <linux/err.h> |
| 27 | #include <linux/sysdev.h> |
| 28 | #include <linux/cpu.h> |
| 29 | |
| 30 | #include <asm/ptrace.h> |
| 31 | #include <asm/atomic.h> |
| 32 | #include <asm/irq.h> |
| 33 | #include <asm/page.h> |
| 34 | #include <asm/pgtable.h> |
| 35 | #include <asm/io.h> |
| 36 | #include <asm/prom.h> |
| 37 | #include <asm/smp.h> |
| 38 | #include <asm/paca.h> |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 39 | #include <asm/machdep.h> |
| 40 | #include <asm/cputable.h> |
| 41 | #include <asm/firmware.h> |
| 42 | #include <asm/system.h> |
| 43 | #include <asm/rtas.h> |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 44 | #include <asm/cputhreads.h> |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 45 | |
| 46 | #include "interrupt.h" |
will schmidt | aa39be0 | 2007-10-30 06:24:19 +1100 | [diff] [blame] | 47 | #include <asm/udbg.h> |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 48 | |
| 49 | #ifdef DEBUG |
| 50 | #define DBG(fmt...) udbg_printf(fmt) |
| 51 | #else |
| 52 | #define DBG(fmt...) |
| 53 | #endif |
| 54 | |
| 55 | /* |
Milton Miller | 6a75a6b | 2008-10-20 15:37:03 +0000 | [diff] [blame] | 56 | * The Primary thread of each non-boot processor was started from the OF client |
| 57 | * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop. |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 58 | */ |
| 59 | static cpumask_t of_spin_map; |
| 60 | |
Olof Johansson | f39b7a5 | 2006-08-11 00:07:08 -0500 | [diff] [blame] | 61 | extern void generic_secondary_smp_init(unsigned long); |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * smp_startup_cpu() - start the given cpu |
| 65 | * |
| 66 | * At boot time, there is nothing to do for primary threads which were |
| 67 | * started from Open Firmware. For anything else, call RTAS with the |
| 68 | * appropriate start location. |
| 69 | * |
| 70 | * Returns: |
| 71 | * 0 - failure |
| 72 | * 1 - success |
| 73 | */ |
| 74 | static inline int __devinit smp_startup_cpu(unsigned int lcpu) |
| 75 | { |
| 76 | int status; |
| 77 | unsigned long start_here = __pa((u32)*((unsigned long *) |
Olof Johansson | f39b7a5 | 2006-08-11 00:07:08 -0500 | [diff] [blame] | 78 | generic_secondary_smp_init)); |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 79 | unsigned int pcpu; |
| 80 | int start_cpu; |
| 81 | |
| 82 | if (cpu_isset(lcpu, of_spin_map)) |
| 83 | /* Already started by OF and sitting in spin loop */ |
| 84 | return 1; |
| 85 | |
| 86 | pcpu = get_hard_smp_processor_id(lcpu); |
| 87 | |
| 88 | /* Fixup atomic count: it exited inside IRQ handler. */ |
Al Viro | b5e2fc1 | 2006-01-12 01:06:01 -0800 | [diff] [blame] | 89 | task_thread_info(paca[lcpu].__current)->preempt_count = 0; |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * If the RTAS start-cpu token does not exist then presume the |
| 93 | * cpu is already spinning. |
| 94 | */ |
| 95 | start_cpu = rtas_token("start-cpu"); |
| 96 | if (start_cpu == RTAS_UNKNOWN_SERVICE) |
| 97 | return 1; |
| 98 | |
| 99 | status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu); |
| 100 | if (status != 0) { |
| 101 | printk(KERN_ERR "start-cpu failed: %i\n", status); |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | return 1; |
| 106 | } |
| 107 | |
| 108 | static void smp_iic_message_pass(int target, int msg) |
| 109 | { |
| 110 | unsigned int i; |
| 111 | |
| 112 | if (target < NR_CPUS) { |
| 113 | iic_cause_IPI(target, msg); |
| 114 | } else { |
| 115 | for_each_online_cpu(i) { |
| 116 | if (target == MSG_ALL_BUT_SELF |
| 117 | && i == smp_processor_id()) |
| 118 | continue; |
| 119 | iic_cause_IPI(i, msg); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | static int __init smp_iic_probe(void) |
| 125 | { |
| 126 | iic_request_IPIs(); |
| 127 | |
| 128 | return cpus_weight(cpu_possible_map); |
| 129 | } |
| 130 | |
Arnd Bergmann | 960cedb | 2008-11-28 09:51:24 +0000 | [diff] [blame] | 131 | static void __devinit smp_cell_setup_cpu(int cpu) |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 132 | { |
| 133 | if (cpu != boot_cpuid) |
| 134 | iic_setup_cpu(); |
Arnd Bergmann | 960cedb | 2008-11-28 09:51:24 +0000 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | * change default DABRX to allow user watchpoints |
| 138 | */ |
| 139 | mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER); |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 140 | } |
| 141 | |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 142 | static void __devinit smp_cell_kick_cpu(int nr) |
| 143 | { |
| 144 | BUG_ON(nr < 0 || nr >= NR_CPUS); |
| 145 | |
| 146 | if (!smp_startup_cpu(nr)) |
| 147 | return; |
| 148 | |
| 149 | /* |
| 150 | * The processor is currently spinning, waiting for the |
| 151 | * cpu_start field to become non-zero After we set cpu_start, |
| 152 | * the processor will continue on to secondary_start |
| 153 | */ |
| 154 | paca[nr].cpu_start = 1; |
| 155 | } |
| 156 | |
| 157 | static int smp_cell_cpu_bootable(unsigned int nr) |
| 158 | { |
| 159 | /* Special case - we inhibit secondary thread startup |
| 160 | * during boot if the user requests it. Odd-numbered |
| 161 | * cpus are assumed to be secondary threads. |
| 162 | */ |
| 163 | if (system_state < SYSTEM_RUNNING && |
| 164 | cpu_has_feature(CPU_FTR_SMT) && |
Benjamin Herrenschmidt | 8d08908 | 2007-10-25 15:27:44 +1000 | [diff] [blame] | 165 | !smt_enabled_at_boot && cpu_thread_in_core(nr) != 0) |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 166 | return 0; |
| 167 | |
| 168 | return 1; |
| 169 | } |
| 170 | static struct smp_ops_t bpa_iic_smp_ops = { |
| 171 | .message_pass = smp_iic_message_pass, |
| 172 | .probe = smp_iic_probe, |
| 173 | .kick_cpu = smp_cell_kick_cpu, |
Arnd Bergmann | 960cedb | 2008-11-28 09:51:24 +0000 | [diff] [blame] | 174 | .setup_cpu = smp_cell_setup_cpu, |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 175 | .cpu_bootable = smp_cell_cpu_bootable, |
| 176 | }; |
| 177 | |
| 178 | /* This is called very early */ |
| 179 | void __init smp_init_cell(void) |
| 180 | { |
| 181 | int i; |
| 182 | |
| 183 | DBG(" -> smp_init_cell()\n"); |
| 184 | |
| 185 | smp_ops = &bpa_iic_smp_ops; |
| 186 | |
| 187 | /* Mark threads which are still spinning in hold loops. */ |
| 188 | if (cpu_has_feature(CPU_FTR_SMT)) { |
| 189 | for_each_present_cpu(i) { |
Milton Miller | 6a75a6b | 2008-10-20 15:37:03 +0000 | [diff] [blame] | 190 | if (cpu_thread_in_core(i) == 0) |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 191 | cpu_set(i, of_spin_map); |
| 192 | } |
| 193 | } else { |
| 194 | of_spin_map = cpu_present_map; |
| 195 | } |
| 196 | |
| 197 | cpu_clear(boot_cpuid, of_spin_map); |
| 198 | |
| 199 | /* Non-lpar has additional take/give timebase */ |
| 200 | if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) { |
Benjamin Herrenschmidt | c4007a2 | 2009-06-16 16:42:50 +0000 | [diff] [blame^] | 201 | smp_ops->give_timebase = rtas_give_timebase; |
| 202 | smp_ops->take_timebase = rtas_take_timebase; |
Arnd Bergmann | 19fe047 | 2005-10-31 20:08:38 -0500 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | DBG(" <- smp_init_cell()\n"); |
| 206 | } |