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