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