Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/s390/kernel/smp.c |
| 3 | * |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999,2007 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com), |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 6 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 7 | * Heiko Carstens (heiko.carstens@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 9 | * based on other smp stuff by |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * (c) 1995 Alan Cox, CymruNET Ltd <alan@cymru.net> |
| 11 | * (c) 1998 Ingo Molnar |
| 12 | * |
| 13 | * We work with logical cpu numbering everywhere we can. The only |
| 14 | * functions using the real cpu address (got from STAP) are the sigp |
| 15 | * functions. For all other functions we use the identity mapping. |
| 16 | * That means that cpu_number_map[i] == i for every cpu. cpu_number_map is |
| 17 | * used e.g. to find the idle task belonging to a logical cpu. Every array |
| 18 | * in the kernel is sorted by the logical cpu number and not by the physical |
| 19 | * one which is causing all the confusion with __cpu_logical_map and |
| 20 | * cpu_number_map in other architectures. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/mm.h> |
| 26 | #include <linux/spinlock.h> |
| 27 | #include <linux/kernel_stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/delay.h> |
| 29 | #include <linux/cache.h> |
| 30 | #include <linux/interrupt.h> |
| 31 | #include <linux/cpu.h> |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 32 | #include <linux/timex.h> |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 33 | #include <linux/bootmem.h> |
Michael Holzheu | 46b05d2 | 2007-02-21 10:55:21 +0100 | [diff] [blame] | 34 | #include <asm/ipl.h> |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 35 | #include <asm/setup.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/sigp.h> |
| 37 | #include <asm/pgalloc.h> |
| 38 | #include <asm/irq.h> |
| 39 | #include <asm/s390_ext.h> |
| 40 | #include <asm/cpcmd.h> |
| 41 | #include <asm/tlbflush.h> |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 42 | #include <asm/timer.h> |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 43 | #include <asm/lowcore.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* |
| 46 | * An array with a pointer the lowcore of every CPU. |
| 47 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | struct _lowcore *lowcore_ptr[NR_CPUS]; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 49 | EXPORT_SYMBOL(lowcore_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 51 | cpumask_t cpu_online_map = CPU_MASK_NONE; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 52 | EXPORT_SYMBOL(cpu_online_map); |
| 53 | |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 54 | cpumask_t cpu_possible_map = CPU_MASK_NONE; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 55 | EXPORT_SYMBOL(cpu_possible_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | static struct task_struct *current_set[NR_CPUS]; |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | static void smp_ext_bitcall(int, ec_bit_sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | /* |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 62 | * Structure and data for __smp_call_function_map(). This is designed to |
| 63 | * minimise static memory requirements. It also looks cleaner. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | */ |
| 65 | static DEFINE_SPINLOCK(call_lock); |
| 66 | |
| 67 | struct call_data_struct { |
| 68 | void (*func) (void *info); |
| 69 | void *info; |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 70 | cpumask_t started; |
| 71 | cpumask_t finished; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | int wait; |
| 73 | }; |
| 74 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 75 | static struct call_data_struct *call_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * 'Call function' interrupt callback |
| 79 | */ |
| 80 | static void do_call_function(void) |
| 81 | { |
| 82 | void (*func) (void *info) = call_data->func; |
| 83 | void *info = call_data->info; |
| 84 | int wait = call_data->wait; |
| 85 | |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 86 | cpu_set(smp_processor_id(), call_data->started); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | (*func)(info); |
| 88 | if (wait) |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 89 | cpu_set(smp_processor_id(), call_data->finished);; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 92 | static void __smp_call_function_map(void (*func) (void *info), void *info, |
| 93 | int nonatomic, int wait, cpumask_t map) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
| 95 | struct call_data_struct data; |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 96 | int cpu, local = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 98 | /* |
Heiko Carstens | 2586416 | 2007-03-05 23:35:41 +0100 | [diff] [blame] | 99 | * Can deadlock when interrupts are disabled or if in wrong context. |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 100 | */ |
Heiko Carstens | 2586416 | 2007-03-05 23:35:41 +0100 | [diff] [blame] | 101 | WARN_ON(irqs_disabled() || in_irq()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 103 | /* |
| 104 | * Check for local function call. We have to have the same call order |
| 105 | * as in on_each_cpu() because of machine_restart_smp(). |
| 106 | */ |
| 107 | if (cpu_isset(smp_processor_id(), map)) { |
| 108 | local = 1; |
| 109 | cpu_clear(smp_processor_id(), map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 112 | cpus_and(map, map, cpu_online_map); |
| 113 | if (cpus_empty(map)) |
| 114 | goto out; |
| 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | data.func = func; |
| 117 | data.info = info; |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 118 | data.started = CPU_MASK_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | data.wait = wait; |
| 120 | if (wait) |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 121 | data.finished = CPU_MASK_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | spin_lock_bh(&call_lock); |
| 124 | call_data = &data; |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 125 | |
| 126 | for_each_cpu_mask(cpu, map) |
| 127 | smp_ext_bitcall(cpu, ec_call_function); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | /* Wait for response */ |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 130 | while (!cpus_equal(map, data.started)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | cpu_relax(); |
| 132 | |
| 133 | if (wait) |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 134 | while (!cpus_equal(map, data.finished)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | cpu_relax(); |
| 136 | |
| 137 | spin_unlock_bh(&call_lock); |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 138 | |
| 139 | out: |
| 140 | local_irq_disable(); |
| 141 | if (local) |
| 142 | func(info); |
| 143 | local_irq_enable(); |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * smp_call_function: |
| 148 | * @func: the function to run; this must be fast and non-blocking |
| 149 | * @info: an arbitrary pointer to pass to the function |
| 150 | * @nonatomic: unused |
| 151 | * @wait: if true, wait (atomically) until function has completed on other CPUs |
| 152 | * |
| 153 | * Run a function on all other CPUs. |
| 154 | * |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 155 | * You must not call this function with disabled interrupts, from a |
| 156 | * hardware interrupt handler or from a bottom half. |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 157 | */ |
| 158 | int smp_call_function(void (*func) (void *info), void *info, int nonatomic, |
| 159 | int wait) |
| 160 | { |
| 161 | cpumask_t map; |
| 162 | |
Heiko Carstens | 2586416 | 2007-03-05 23:35:41 +0100 | [diff] [blame] | 163 | preempt_disable(); |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 164 | map = cpu_online_map; |
| 165 | cpu_clear(smp_processor_id(), map); |
| 166 | __smp_call_function_map(func, info, nonatomic, wait, map); |
Heiko Carstens | 2586416 | 2007-03-05 23:35:41 +0100 | [diff] [blame] | 167 | preempt_enable(); |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | EXPORT_SYMBOL(smp_call_function); |
| 171 | |
| 172 | /* |
Heiko Carstens | 3bb447f | 2007-07-27 12:29:08 +0200 | [diff] [blame^] | 173 | * smp_call_function_single: |
| 174 | * @cpu: the CPU where func should run |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 175 | * @func: the function to run; this must be fast and non-blocking |
| 176 | * @info: an arbitrary pointer to pass to the function |
| 177 | * @nonatomic: unused |
| 178 | * @wait: if true, wait (atomically) until function has completed on other CPUs |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 179 | * |
| 180 | * Run a function on one processor. |
| 181 | * |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 182 | * You must not call this function with disabled interrupts, from a |
| 183 | * hardware interrupt handler or from a bottom half. |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 184 | */ |
Heiko Carstens | 3bb447f | 2007-07-27 12:29:08 +0200 | [diff] [blame^] | 185 | int smp_call_function_single(int cpu, void (*func) (void *info), void *info, |
| 186 | int nonatomic, int wait) |
Jan Glauber | 63db6e8 | 2007-02-21 10:55:06 +0100 | [diff] [blame] | 187 | { |
Heiko Carstens | 2586416 | 2007-03-05 23:35:41 +0100 | [diff] [blame] | 188 | preempt_disable(); |
Heiko Carstens | 3bb447f | 2007-07-27 12:29:08 +0200 | [diff] [blame^] | 189 | __smp_call_function_map(func, info, nonatomic, wait, |
| 190 | cpumask_of_cpu(cpu)); |
Heiko Carstens | 2586416 | 2007-03-05 23:35:41 +0100 | [diff] [blame] | 191 | preempt_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | return 0; |
| 193 | } |
Heiko Carstens | 3bb447f | 2007-07-27 12:29:08 +0200 | [diff] [blame^] | 194 | EXPORT_SYMBOL(smp_call_function_single); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 196 | static void do_send_stop(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 198 | int cpu, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 200 | /* stop all processors */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | for_each_online_cpu(cpu) { |
| 202 | if (cpu == smp_processor_id()) |
| 203 | continue; |
| 204 | do { |
| 205 | rc = signal_processor(cpu, sigp_stop); |
| 206 | } while (rc == sigp_busy); |
| 207 | } |
| 208 | } |
| 209 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 210 | static void do_store_status(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 212 | int cpu, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 214 | /* store status of all processors in their lowcores (real 0) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | for_each_online_cpu(cpu) { |
| 216 | if (cpu == smp_processor_id()) |
| 217 | continue; |
| 218 | do { |
| 219 | rc = signal_processor_p( |
| 220 | (__u32)(unsigned long) lowcore_ptr[cpu], cpu, |
| 221 | sigp_store_status_at_address); |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 222 | } while (rc == sigp_busy); |
| 223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 226 | static void do_wait_for_stop(void) |
Heiko Carstens | c6b5b84 | 2006-12-04 15:40:33 +0100 | [diff] [blame] | 227 | { |
| 228 | int cpu; |
| 229 | |
| 230 | /* Wait for all other cpus to enter stopped state */ |
| 231 | for_each_online_cpu(cpu) { |
| 232 | if (cpu == smp_processor_id()) |
| 233 | continue; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 234 | while (!smp_cpu_not_running(cpu)) |
Heiko Carstens | c6b5b84 | 2006-12-04 15:40:33 +0100 | [diff] [blame] | 235 | cpu_relax(); |
| 236 | } |
| 237 | } |
| 238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | /* |
| 240 | * this function sends a 'stop' sigp to all other CPUs in the system. |
| 241 | * it goes straight through. |
| 242 | */ |
| 243 | void smp_send_stop(void) |
| 244 | { |
Heiko Carstens | c6b5b84 | 2006-12-04 15:40:33 +0100 | [diff] [blame] | 245 | /* Disable all interrupts/machine checks */ |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 246 | __load_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK); |
Heiko Carstens | c6b5b84 | 2006-12-04 15:40:33 +0100 | [diff] [blame] | 247 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 248 | /* write magic number to zero page (absolute 0) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | lowcore_ptr[smp_processor_id()]->panic_magic = __PANIC_MAGIC; |
| 250 | |
| 251 | /* stop other processors. */ |
| 252 | do_send_stop(); |
| 253 | |
Heiko Carstens | c6b5b84 | 2006-12-04 15:40:33 +0100 | [diff] [blame] | 254 | /* wait until other processors are stopped */ |
| 255 | do_wait_for_stop(); |
| 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | /* store status of other processors. */ |
| 258 | do_store_status(); |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Reboot, halt and power_off routines for SMP. |
| 263 | */ |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 264 | void machine_restart_smp(char *__unused) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
Heiko Carstens | c6b5b84 | 2006-12-04 15:40:33 +0100 | [diff] [blame] | 266 | smp_send_stop(); |
| 267 | do_reipl(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void machine_halt_smp(void) |
| 271 | { |
Heiko Carstens | c6b5b84 | 2006-12-04 15:40:33 +0100 | [diff] [blame] | 272 | smp_send_stop(); |
| 273 | if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0) |
| 274 | __cpcmd(vmhalt_cmd, NULL, 0, NULL); |
| 275 | signal_processor(smp_processor_id(), sigp_stop_and_store_status); |
| 276 | for (;;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | void machine_power_off_smp(void) |
| 280 | { |
Heiko Carstens | c6b5b84 | 2006-12-04 15:40:33 +0100 | [diff] [blame] | 281 | smp_send_stop(); |
| 282 | if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0) |
| 283 | __cpcmd(vmpoff_cmd, NULL, 0, NULL); |
| 284 | signal_processor(smp_processor_id(), sigp_stop_and_store_status); |
| 285 | for (;;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /* |
| 289 | * This is the main routine where commands issued by other |
| 290 | * cpus are handled. |
| 291 | */ |
| 292 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 293 | static void do_ext_call_interrupt(__u16 code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 295 | unsigned long bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 297 | /* |
| 298 | * handle bit signal external calls |
| 299 | * |
| 300 | * For the ec_schedule signal we have to do nothing. All the work |
| 301 | * is done automatically when we return from the interrupt. |
| 302 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | bits = xchg(&S390_lowcore.ext_call_fast, 0); |
| 304 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 305 | if (test_bit(ec_call_function, &bits)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | do_call_function(); |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * Send an external call sigp to another cpu and return without waiting |
| 311 | * for its completion. |
| 312 | */ |
| 313 | static void smp_ext_bitcall(int cpu, ec_bit_sig sig) |
| 314 | { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 315 | /* |
| 316 | * Set signaling bit in lowcore of target cpu and kick it |
| 317 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast); |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 319 | while (signal_processor(cpu, sigp_emergency_signal) == sigp_busy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | udelay(10); |
| 321 | } |
| 322 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 323 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /* |
| 325 | * this function sends a 'purge tlb' signal to another CPU. |
| 326 | */ |
| 327 | void smp_ptlb_callback(void *info) |
| 328 | { |
| 329 | local_flush_tlb(); |
| 330 | } |
| 331 | |
| 332 | void smp_ptlb_all(void) |
| 333 | { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 334 | on_each_cpu(smp_ptlb_callback, NULL, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | EXPORT_SYMBOL(smp_ptlb_all); |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 337 | #endif /* ! CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | /* |
| 340 | * this function sends a 'reschedule' IPI to another CPU. |
| 341 | * it goes straight through and wastes no time serializing |
| 342 | * anything. Worst case is that we lose a reschedule ... |
| 343 | */ |
| 344 | void smp_send_reschedule(int cpu) |
| 345 | { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 346 | smp_ext_bitcall(cpu, ec_schedule); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /* |
| 350 | * parameter area for the set/clear control bit callbacks |
| 351 | */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 352 | struct ec_creg_mask_parms { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | unsigned long orvals[16]; |
| 354 | unsigned long andvals[16]; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 355 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * callback for setting/clearing control bits |
| 359 | */ |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 360 | static void smp_ctl_bit_callback(void *info) |
| 361 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 362 | struct ec_creg_mask_parms *pp = info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | unsigned long cregs[16]; |
| 364 | int i; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 365 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 366 | __ctl_store(cregs, 0, 15); |
| 367 | for (i = 0; i <= 15; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | cregs[i] = (cregs[i] & pp->andvals[i]) | pp->orvals[i]; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 369 | __ctl_load(cregs, 0, 15); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | /* |
| 373 | * Set a bit in a control register of all cpus |
| 374 | */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 375 | void smp_ctl_set_bit(int cr, int bit) |
| 376 | { |
| 377 | struct ec_creg_mask_parms parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 379 | memset(&parms.orvals, 0, sizeof(parms.orvals)); |
| 380 | memset(&parms.andvals, 0xff, sizeof(parms.andvals)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | parms.orvals[cr] = 1 << bit; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 382 | on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 384 | EXPORT_SYMBOL(smp_ctl_set_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
| 386 | /* |
| 387 | * Clear a bit in a control register of all cpus |
| 388 | */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 389 | void smp_ctl_clear_bit(int cr, int bit) |
| 390 | { |
| 391 | struct ec_creg_mask_parms parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 393 | memset(&parms.orvals, 0, sizeof(parms.orvals)); |
| 394 | memset(&parms.andvals, 0xff, sizeof(parms.andvals)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | parms.andvals[cr] = ~(1L << bit); |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 396 | on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 398 | EXPORT_SYMBOL(smp_ctl_clear_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 400 | #if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_ZFCPDUMP_MODULE) |
| 401 | |
| 402 | /* |
| 403 | * zfcpdump_prefix_array holds prefix registers for the following scenario: |
| 404 | * 64 bit zfcpdump kernel and 31 bit kernel which is to be dumped. We have to |
| 405 | * save its prefix registers, since they get lost, when switching from 31 bit |
| 406 | * to 64 bit. |
| 407 | */ |
| 408 | unsigned int zfcpdump_prefix_array[NR_CPUS + 1] \ |
| 409 | __attribute__((__section__(".data"))); |
| 410 | |
Heiko Carstens | 285f672 | 2007-07-10 11:24:13 +0200 | [diff] [blame] | 411 | static void __init smp_get_save_area(unsigned int cpu, unsigned int phy_cpu) |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 412 | { |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 413 | if (ipl_info.type != IPL_TYPE_FCP_DUMP) |
| 414 | return; |
Heiko Carstens | 285f672 | 2007-07-10 11:24:13 +0200 | [diff] [blame] | 415 | if (cpu >= NR_CPUS) { |
| 416 | printk(KERN_WARNING "Registers for cpu %i not saved since dump " |
| 417 | "kernel was compiled with NR_CPUS=%i\n", cpu, NR_CPUS); |
| 418 | return; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 419 | } |
Heiko Carstens | 285f672 | 2007-07-10 11:24:13 +0200 | [diff] [blame] | 420 | zfcpdump_save_areas[cpu] = alloc_bootmem(sizeof(union save_area)); |
| 421 | __cpu_logical_map[1] = (__u16) phy_cpu; |
| 422 | while (signal_processor(1, sigp_stop_and_store_status) == sigp_busy) |
| 423 | cpu_relax(); |
| 424 | memcpy(zfcpdump_save_areas[cpu], |
| 425 | (void *)(unsigned long) store_prefix() + SAVE_AREA_BASE, |
| 426 | SAVE_AREA_SIZE); |
| 427 | #ifdef CONFIG_64BIT |
| 428 | /* copy original prefix register */ |
| 429 | zfcpdump_save_areas[cpu]->s390x.pref_reg = zfcpdump_prefix_array[cpu]; |
| 430 | #endif |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | union save_area *zfcpdump_save_areas[NR_CPUS + 1]; |
| 434 | EXPORT_SYMBOL_GPL(zfcpdump_save_areas); |
| 435 | |
| 436 | #else |
Heiko Carstens | 285f672 | 2007-07-10 11:24:13 +0200 | [diff] [blame] | 437 | |
| 438 | static inline void smp_get_save_area(unsigned int cpu, unsigned int phy_cpu) { } |
| 439 | |
| 440 | #endif /* CONFIG_ZFCPDUMP || CONFIG_ZFCPDUMP_MODULE */ |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | /* |
| 443 | * Lets check how many CPUs we have. |
| 444 | */ |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 445 | static unsigned int __init smp_count_cpus(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 447 | unsigned int cpu, num_cpus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | __u16 boot_cpu_addr; |
| 449 | |
| 450 | /* |
| 451 | * cpu 0 is the boot cpu. See smp_prepare_boot_cpu. |
| 452 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | boot_cpu_addr = S390_lowcore.cpu_data.cpu_addr; |
| 454 | current_thread_info()->cpu = 0; |
| 455 | num_cpus = 1; |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 456 | for (cpu = 0; cpu <= 65535; cpu++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | if ((__u16) cpu == boot_cpu_addr) |
| 458 | continue; |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 459 | __cpu_logical_map[1] = (__u16) cpu; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 460 | if (signal_processor(1, sigp_sense) == sigp_not_operational) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | continue; |
Heiko Carstens | 285f672 | 2007-07-10 11:24:13 +0200 | [diff] [blame] | 462 | smp_get_save_area(num_cpus, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | num_cpus++; |
| 464 | } |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 465 | printk("Detected %d CPU's\n", (int) num_cpus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | printk("Boot cpu address %2X\n", boot_cpu_addr); |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 467 | return num_cpus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /* |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 471 | * Activate a secondary processor. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | */ |
Heiko Carstens | ea1f4ee | 2007-05-31 17:38:05 +0200 | [diff] [blame] | 473 | int __cpuinit start_secondary(void *cpuvoid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 475 | /* Setup the cpu */ |
| 476 | cpu_init(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 477 | preempt_disable(); |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 478 | /* Enable TOD clock interrupts on the secondary cpu. */ |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 479 | init_cpu_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | #ifdef CONFIG_VIRT_TIMER |
Martin Schwidefsky | d54853e | 2007-02-05 21:18:19 +0100 | [diff] [blame] | 481 | /* Enable cpu timer interrupts on the secondary cpu. */ |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 482 | init_cpu_vtimer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | /* Enable pfault pseudo page faults on this cpu. */ |
Heiko Carstens | 29b08d2 | 2006-12-04 15:40:40 +0100 | [diff] [blame] | 485 | pfault_init(); |
| 486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | /* Mark this cpu as online */ |
| 488 | cpu_set(smp_processor_id(), cpu_online_map); |
| 489 | /* Switch on interrupts */ |
| 490 | local_irq_enable(); |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 491 | /* Print info about this processor */ |
| 492 | print_cpu_info(&S390_lowcore.cpu_data); |
| 493 | /* cpu_idle will call schedule for us */ |
| 494 | cpu_idle(); |
| 495 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static void __init smp_create_idle(unsigned int cpu) |
| 499 | { |
| 500 | struct task_struct *p; |
| 501 | |
| 502 | /* |
| 503 | * don't care about the psw and regs settings since we'll never |
| 504 | * reschedule the forked task. |
| 505 | */ |
| 506 | p = fork_idle(cpu); |
| 507 | if (IS_ERR(p)) |
| 508 | panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p)); |
| 509 | current_set[cpu] = p; |
| 510 | } |
| 511 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 512 | static int cpu_stopped(int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
| 514 | __u32 status; |
| 515 | |
| 516 | /* Check for stopped state */ |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 517 | if (signal_processor_ps(&status, 0, cpu, sigp_sense) == |
| 518 | sigp_status_stored) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | if (status & 0x40) |
| 520 | return 1; |
| 521 | } |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | /* Upping and downing of CPUs */ |
| 526 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 527 | int __cpu_up(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | struct task_struct *idle; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 530 | struct _lowcore *cpu_lowcore; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | struct stack_frame *sf; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 532 | sigp_ccode ccode; |
| 533 | int curr_cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | for (curr_cpu = 0; curr_cpu <= 65535; curr_cpu++) { |
| 536 | __cpu_logical_map[cpu] = (__u16) curr_cpu; |
| 537 | if (cpu_stopped(cpu)) |
| 538 | break; |
| 539 | } |
| 540 | |
| 541 | if (!cpu_stopped(cpu)) |
| 542 | return -ENODEV; |
| 543 | |
| 544 | ccode = signal_processor_p((__u32)(unsigned long)(lowcore_ptr[cpu]), |
| 545 | cpu, sigp_set_prefix); |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 546 | if (ccode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | printk("sigp_set_prefix failed for cpu %d " |
| 548 | "with condition code %d\n", |
| 549 | (int) cpu, (int) ccode); |
| 550 | return -EIO; |
| 551 | } |
| 552 | |
| 553 | idle = current_set[cpu]; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 554 | cpu_lowcore = lowcore_ptr[cpu]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | cpu_lowcore->kernel_stack = (unsigned long) |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 556 | task_stack_page(idle) + THREAD_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | sf = (struct stack_frame *) (cpu_lowcore->kernel_stack |
| 558 | - sizeof(struct pt_regs) |
| 559 | - sizeof(struct stack_frame)); |
| 560 | memset(sf, 0, sizeof(struct stack_frame)); |
| 561 | sf->gprs[9] = (unsigned long) sf; |
| 562 | cpu_lowcore->save_area[15] = (unsigned long) sf; |
| 563 | __ctl_store(cpu_lowcore->cregs_save_area[0], 0, 15); |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 564 | asm volatile( |
| 565 | " stam 0,15,0(%0)" |
| 566 | : : "a" (&cpu_lowcore->access_regs_save_area) : "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | cpu_lowcore->percpu_offset = __per_cpu_offset[cpu]; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 568 | cpu_lowcore->current_task = (unsigned long) idle; |
| 569 | cpu_lowcore->cpu_data.cpu_nr = cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | eieio(); |
Michael Ryan | 699ff13 | 2006-03-24 03:15:17 -0800 | [diff] [blame] | 571 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 572 | while (signal_processor(cpu, sigp_restart) == sigp_busy) |
Michael Ryan | 699ff13 | 2006-03-24 03:15:17 -0800 | [diff] [blame] | 573 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | while (!cpu_online(cpu)) |
| 576 | cpu_relax(); |
| 577 | return 0; |
| 578 | } |
| 579 | |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 580 | static unsigned int __initdata additional_cpus; |
Heiko Carstens | 37a3302 | 2006-02-17 13:52:47 -0800 | [diff] [blame] | 581 | static unsigned int __initdata possible_cpus; |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 582 | |
| 583 | void __init smp_setup_cpu_possible_map(void) |
| 584 | { |
Heiko Carstens | 5433045 | 2006-02-17 13:52:48 -0800 | [diff] [blame] | 585 | unsigned int phy_cpus, pos_cpus, cpu; |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 586 | |
Heiko Carstens | 5433045 | 2006-02-17 13:52:48 -0800 | [diff] [blame] | 587 | phy_cpus = smp_count_cpus(); |
| 588 | pos_cpus = min(phy_cpus + additional_cpus, (unsigned int) NR_CPUS); |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 589 | |
Heiko Carstens | 37a3302 | 2006-02-17 13:52:47 -0800 | [diff] [blame] | 590 | if (possible_cpus) |
Heiko Carstens | 5433045 | 2006-02-17 13:52:48 -0800 | [diff] [blame] | 591 | pos_cpus = min(possible_cpus, (unsigned int) NR_CPUS); |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 592 | |
Heiko Carstens | 5433045 | 2006-02-17 13:52:48 -0800 | [diff] [blame] | 593 | for (cpu = 0; cpu < pos_cpus; cpu++) |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 594 | cpu_set(cpu, cpu_possible_map); |
| 595 | |
Heiko Carstens | 5433045 | 2006-02-17 13:52:48 -0800 | [diff] [blame] | 596 | phy_cpus = min(phy_cpus, pos_cpus); |
| 597 | |
| 598 | for (cpu = 0; cpu < phy_cpus; cpu++) |
| 599 | cpu_set(cpu, cpu_present_map); |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | #ifdef CONFIG_HOTPLUG_CPU |
| 603 | |
| 604 | static int __init setup_additional_cpus(char *s) |
| 605 | { |
| 606 | additional_cpus = simple_strtoul(s, NULL, 0); |
| 607 | return 0; |
| 608 | } |
| 609 | early_param("additional_cpus", setup_additional_cpus); |
| 610 | |
Heiko Carstens | 37a3302 | 2006-02-17 13:52:47 -0800 | [diff] [blame] | 611 | static int __init setup_possible_cpus(char *s) |
| 612 | { |
| 613 | possible_cpus = simple_strtoul(s, NULL, 0); |
| 614 | return 0; |
| 615 | } |
| 616 | early_param("possible_cpus", setup_possible_cpus); |
| 617 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 618 | int __cpu_disable(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 620 | struct ec_creg_mask_parms cr_parms; |
Zwane Mwaikambo | f370513 | 2005-06-25 14:54:50 -0700 | [diff] [blame] | 621 | int cpu = smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Zwane Mwaikambo | f370513 | 2005-06-25 14:54:50 -0700 | [diff] [blame] | 623 | cpu_clear(cpu, cpu_online_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | /* Disable pfault pseudo page faults on this cpu. */ |
Heiko Carstens | 29b08d2 | 2006-12-04 15:40:40 +0100 | [diff] [blame] | 626 | pfault_fini(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 628 | memset(&cr_parms.orvals, 0, sizeof(cr_parms.orvals)); |
| 629 | memset(&cr_parms.andvals, 0xff, sizeof(cr_parms.andvals)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 631 | /* disable all external interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | cr_parms.orvals[0] = 0; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 633 | cr_parms.andvals[0] = ~(1 << 15 | 1 << 14 | 1 << 13 | 1 << 12 | |
| 634 | 1 << 11 | 1 << 10 | 1 << 6 | 1 << 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | /* disable all I/O interrupts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | cr_parms.orvals[6] = 0; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 637 | cr_parms.andvals[6] = ~(1 << 31 | 1 << 30 | 1 << 29 | 1 << 28 | |
| 638 | 1 << 27 | 1 << 26 | 1 << 25 | 1 << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | /* disable most machine checks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | cr_parms.orvals[14] = 0; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 641 | cr_parms.andvals[14] = ~(1 << 28 | 1 << 27 | 1 << 26 | |
| 642 | 1 << 25 | 1 << 24); |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | smp_ctl_bit_callback(&cr_parms); |
| 645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | return 0; |
| 647 | } |
| 648 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 649 | void __cpu_die(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | { |
| 651 | /* Wait until target cpu is down */ |
| 652 | while (!smp_cpu_not_running(cpu)) |
| 653 | cpu_relax(); |
| 654 | printk("Processor %d spun down\n", cpu); |
| 655 | } |
| 656 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 657 | void cpu_die(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | { |
| 659 | idle_task_exit(); |
| 660 | signal_processor(smp_processor_id(), sigp_stop); |
| 661 | BUG(); |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 662 | for (;;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 665 | #endif /* CONFIG_HOTPLUG_CPU */ |
| 666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | /* |
| 668 | * Cycle through the processors and setup structures. |
| 669 | */ |
| 670 | |
| 671 | void __init smp_prepare_cpus(unsigned int max_cpus) |
| 672 | { |
| 673 | unsigned long stack; |
| 674 | unsigned int cpu; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 675 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 677 | /* request the 0x1201 emergency signal external interrupt */ |
| 678 | if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0) |
| 679 | panic("Couldn't request external interrupt 0x1201"); |
| 680 | memset(lowcore_ptr, 0, sizeof(lowcore_ptr)); |
| 681 | /* |
| 682 | * Initialize prefix pages and stacks for all possible cpus |
| 683 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | print_cpu_info(&S390_lowcore.cpu_data); |
| 685 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 686 | for_each_possible_cpu(i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | lowcore_ptr[i] = (struct _lowcore *) |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 688 | __get_free_pages(GFP_KERNEL | GFP_DMA, |
| 689 | sizeof(void*) == 8 ? 1 : 0); |
| 690 | stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER); |
| 691 | if (!lowcore_ptr[i] || !stack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | panic("smp_boot_cpus failed to allocate memory\n"); |
| 693 | |
| 694 | *(lowcore_ptr[i]) = S390_lowcore; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 695 | lowcore_ptr[i]->async_stack = stack + ASYNC_SIZE; |
| 696 | stack = __get_free_pages(GFP_KERNEL, 0); |
| 697 | if (!stack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | panic("smp_boot_cpus failed to allocate memory\n"); |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 699 | lowcore_ptr[i]->panic_stack = stack + PAGE_SIZE; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 700 | #ifndef CONFIG_64BIT |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 701 | if (MACHINE_HAS_IEEE) { |
| 702 | lowcore_ptr[i]->extended_save_area_addr = |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 703 | (__u32) __get_free_pages(GFP_KERNEL, 0); |
| 704 | if (!lowcore_ptr[i]->extended_save_area_addr) |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 705 | panic("smp_boot_cpus failed to " |
| 706 | "allocate memory\n"); |
| 707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | #endif |
| 709 | } |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 710 | #ifndef CONFIG_64BIT |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 711 | if (MACHINE_HAS_IEEE) |
| 712 | ctl_set_bit(14, 29); /* enable extended save area */ |
| 713 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | set_prefix((u32)(unsigned long) lowcore_ptr[smp_processor_id()]); |
| 715 | |
KAMEZAWA Hiroyuki | 97db7fb | 2006-03-31 02:30:26 -0800 | [diff] [blame] | 716 | for_each_possible_cpu(cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | if (cpu != smp_processor_id()) |
| 718 | smp_create_idle(cpu); |
| 719 | } |
| 720 | |
Heiko Carstens | ea1f4ee | 2007-05-31 17:38:05 +0200 | [diff] [blame] | 721 | void __init smp_prepare_boot_cpu(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
| 723 | BUG_ON(smp_processor_id() != 0); |
| 724 | |
| 725 | cpu_set(0, cpu_online_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | S390_lowcore.percpu_offset = __per_cpu_offset[0]; |
| 727 | current_set[0] = current; |
| 728 | } |
| 729 | |
Heiko Carstens | ea1f4ee | 2007-05-31 17:38:05 +0200 | [diff] [blame] | 730 | void __init smp_cpus_done(unsigned int max_cpus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | { |
Heiko Carstens | 5433045 | 2006-02-17 13:52:48 -0800 | [diff] [blame] | 732 | cpu_present_map = cpu_possible_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | /* |
| 736 | * the frequency of the profiling timer can be changed |
| 737 | * by writing a multiplier value into /proc/profile. |
| 738 | * |
| 739 | * usually you want to run this on all CPUs ;) |
| 740 | */ |
| 741 | int setup_profiling_timer(unsigned int multiplier) |
| 742 | { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 743 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static DEFINE_PER_CPU(struct cpu, cpu_devices); |
| 747 | |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 748 | static ssize_t show_capability(struct sys_device *dev, char *buf) |
| 749 | { |
| 750 | unsigned int capability; |
| 751 | int rc; |
| 752 | |
| 753 | rc = get_cpu_capability(&capability); |
| 754 | if (rc) |
| 755 | return rc; |
| 756 | return sprintf(buf, "%u\n", capability); |
| 757 | } |
| 758 | static SYSDEV_ATTR(capability, 0444, show_capability, NULL); |
| 759 | |
| 760 | static int __cpuinit smp_cpu_notify(struct notifier_block *self, |
| 761 | unsigned long action, void *hcpu) |
| 762 | { |
| 763 | unsigned int cpu = (unsigned int)(long)hcpu; |
| 764 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
| 765 | struct sys_device *s = &c->sysdev; |
| 766 | |
| 767 | switch (action) { |
| 768 | case CPU_ONLINE: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 769 | case CPU_ONLINE_FROZEN: |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 770 | if (sysdev_create_file(s, &attr_capability)) |
| 771 | return NOTIFY_BAD; |
| 772 | break; |
| 773 | case CPU_DEAD: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 774 | case CPU_DEAD_FROZEN: |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 775 | sysdev_remove_file(s, &attr_capability); |
| 776 | break; |
| 777 | } |
| 778 | return NOTIFY_OK; |
| 779 | } |
| 780 | |
| 781 | static struct notifier_block __cpuinitdata smp_cpu_nb = { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 782 | .notifier_call = smp_cpu_notify, |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 783 | }; |
| 784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | static int __init topology_init(void) |
| 786 | { |
| 787 | int cpu; |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 788 | |
| 789 | register_cpu_notifier(&smp_cpu_nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
KAMEZAWA Hiroyuki | 97db7fb | 2006-03-31 02:30:26 -0800 | [diff] [blame] | 791 | for_each_possible_cpu(cpu) { |
Heiko Carstens | 6721f77 | 2007-01-09 10:18:44 +0100 | [diff] [blame] | 792 | struct cpu *c = &per_cpu(cpu_devices, cpu); |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 793 | struct sys_device *s = &c->sysdev; |
Heiko Carstens | 6721f77 | 2007-01-09 10:18:44 +0100 | [diff] [blame] | 794 | |
| 795 | c->hotpluggable = 1; |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 796 | register_cpu(c, cpu); |
| 797 | if (!cpu_online(cpu)) |
| 798 | continue; |
| 799 | s = &c->sysdev; |
| 800 | sysdev_create_file(s, &attr_capability); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | } |
| 802 | return 0; |
| 803 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | subsys_initcall(topology_init); |