Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 2 | * SMP related functions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999,2012 |
| 5 | * Author(s): Denis Joseph Barrow, |
| 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 | * |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 13 | * The code outside of smp.c uses logical cpu numbers, only smp.c does |
| 14 | * the translation of logical to physical cpu ids. All new code that |
| 15 | * operates on physical cpu numbers needs to go into smp.c. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 18 | #define KMSG_COMPONENT "cpu" |
| 19 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 20 | |
Heiko Carstens | f230886 | 2011-01-05 12:48:08 +0100 | [diff] [blame] | 21 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/mm.h> |
Alexey Dobriyan | 4e950f6 | 2007-07-30 02:36:13 +0400 | [diff] [blame] | 25 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/spinlock.h> |
| 27 | #include <linux/kernel_stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/interrupt.h> |
Christian Borntraeger | 3324e60 | 2009-03-26 15:23:56 +0100 | [diff] [blame] | 30 | #include <linux/irqflags.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/cpu.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 33 | #include <linux/crash_dump.h> |
Heiko Carstens | cbb870c | 2010-02-26 22:37:43 +0100 | [diff] [blame] | 34 | #include <asm/asm-offsets.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/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/tlbflush.h> |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 39 | #include <asm/timer.h> |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 40 | #include <asm/lowcore.h> |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 41 | #include <asm/sclp.h> |
Martin Schwidefsky | c742b31 | 2008-12-31 15:11:42 +0100 | [diff] [blame] | 42 | #include <asm/vdso.h> |
Michael Holzheu | 3ab121a | 2012-03-11 11:59:32 -0400 | [diff] [blame] | 43 | #include <asm/debug.h> |
Michael Holzheu | 4857d4b | 2012-03-11 11:59:34 -0400 | [diff] [blame^] | 44 | #include <asm/os_info.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 45 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 47 | enum { |
| 48 | sigp_sense = 1, |
| 49 | sigp_external_call = 2, |
| 50 | sigp_emergency_signal = 3, |
| 51 | sigp_start = 4, |
| 52 | sigp_stop = 5, |
| 53 | sigp_restart = 6, |
| 54 | sigp_stop_and_store_status = 9, |
| 55 | sigp_initial_cpu_reset = 11, |
| 56 | sigp_cpu_reset = 12, |
| 57 | sigp_set_prefix = 13, |
| 58 | sigp_store_status_at_address = 14, |
| 59 | sigp_store_extended_status_at_address = 15, |
| 60 | sigp_set_architecture = 18, |
| 61 | sigp_conditional_emergency_signal = 19, |
| 62 | sigp_sense_running = 21, |
| 63 | }; |
Heiko Carstens | fb380aa | 2010-01-13 20:44:37 +0100 | [diff] [blame] | 64 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 65 | enum { |
| 66 | sigp_order_code_accepted = 0, |
| 67 | sigp_status_stored = 1, |
| 68 | sigp_busy = 2, |
| 69 | sigp_not_operational = 3, |
| 70 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 72 | enum { |
| 73 | ec_schedule = 0, |
| 74 | ec_call_function, |
| 75 | ec_call_function_single, |
| 76 | ec_stop_cpu, |
| 77 | }; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 78 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 79 | enum { |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 80 | CPU_STATE_STANDBY, |
| 81 | CPU_STATE_CONFIGURED, |
| 82 | }; |
| 83 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 84 | struct pcpu { |
| 85 | struct cpu cpu; |
| 86 | struct task_struct *idle; /* idle process for the cpu */ |
| 87 | struct _lowcore *lowcore; /* lowcore page(s) for the cpu */ |
| 88 | unsigned long async_stack; /* async stack for the cpu */ |
| 89 | unsigned long panic_stack; /* panic stack for the cpu */ |
| 90 | unsigned long ec_mask; /* bit mask for ec_xxx functions */ |
| 91 | int state; /* physical cpu state */ |
| 92 | u32 status; /* last status received via sigp */ |
| 93 | u16 address; /* physical cpu address */ |
| 94 | }; |
| 95 | |
| 96 | static u8 boot_cpu_type; |
| 97 | static u16 boot_cpu_address; |
| 98 | static struct pcpu pcpu_devices[NR_CPUS]; |
| 99 | |
Heiko Carstens | dbd70fb | 2008-04-17 07:46:12 +0200 | [diff] [blame] | 100 | DEFINE_MUTEX(smp_cpu_state_mutex); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 101 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 102 | /* |
| 103 | * Signal processor helper functions. |
| 104 | */ |
| 105 | static inline int __pcpu_sigp(u16 addr, u8 order, u32 parm, u32 *status) |
Heiko Carstens | 5c0b912 | 2009-09-11 10:29:05 +0200 | [diff] [blame] | 106 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 107 | register unsigned int reg1 asm ("1") = parm; |
| 108 | int cc; |
Heiko Carstens | 5c0b912 | 2009-09-11 10:29:05 +0200 | [diff] [blame] | 109 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 110 | asm volatile( |
| 111 | " sigp %1,%2,0(%3)\n" |
| 112 | " ipm %0\n" |
| 113 | " srl %0,28\n" |
| 114 | : "=d" (cc), "+d" (reg1) : "d" (addr), "a" (order) : "cc"); |
| 115 | if (status && cc == 1) |
| 116 | *status = reg1; |
| 117 | return cc; |
Heiko Carstens | 5c0b912 | 2009-09-11 10:29:05 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 120 | static inline int __pcpu_sigp_relax(u16 addr, u8 order, u32 parm, u32 *status) |
Heiko Carstens | a93b8ec | 2010-02-26 22:37:35 +0100 | [diff] [blame] | 121 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 122 | int cc; |
| 123 | |
| 124 | while (1) { |
| 125 | cc = __pcpu_sigp(addr, order, parm, status); |
| 126 | if (cc != sigp_busy) |
| 127 | return cc; |
| 128 | cpu_relax(); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | static int pcpu_sigp_retry(struct pcpu *pcpu, u8 order, u32 parm) |
| 133 | { |
| 134 | int cc, retry; |
| 135 | |
| 136 | for (retry = 0; ; retry++) { |
| 137 | cc = __pcpu_sigp(pcpu->address, order, parm, &pcpu->status); |
| 138 | if (cc != sigp_busy) |
| 139 | break; |
| 140 | if (retry >= 3) |
| 141 | udelay(10); |
| 142 | } |
| 143 | return cc; |
| 144 | } |
| 145 | |
| 146 | static inline int pcpu_stopped(struct pcpu *pcpu) |
| 147 | { |
| 148 | if (__pcpu_sigp(pcpu->address, sigp_sense, |
| 149 | 0, &pcpu->status) != sigp_status_stored) |
| 150 | return 0; |
| 151 | /* Check for stopped and check stop state */ |
| 152 | return !!(pcpu->status & 0x50); |
| 153 | } |
| 154 | |
| 155 | static inline int pcpu_running(struct pcpu *pcpu) |
| 156 | { |
| 157 | if (__pcpu_sigp(pcpu->address, sigp_sense_running, |
| 158 | 0, &pcpu->status) != sigp_status_stored) |
| 159 | return 1; |
| 160 | /* Check for running status */ |
| 161 | return !(pcpu->status & 0x400); |
Heiko Carstens | a93b8ec | 2010-02-26 22:37:35 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Michael Holzheu | 1943f53 | 2011-10-30 15:16:38 +0100 | [diff] [blame] | 164 | /* |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 165 | * Find struct pcpu by cpu address. |
Michael Holzheu | 1943f53 | 2011-10-30 15:16:38 +0100 | [diff] [blame] | 166 | */ |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 167 | static struct pcpu *pcpu_find_address(const struct cpumask *mask, int address) |
Michael Holzheu | 1943f53 | 2011-10-30 15:16:38 +0100 | [diff] [blame] | 168 | { |
| 169 | int cpu; |
| 170 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 171 | for_each_cpu(cpu, mask) |
| 172 | if (pcpu_devices[cpu].address == address) |
| 173 | return pcpu_devices + cpu; |
| 174 | return NULL; |
| 175 | } |
| 176 | |
| 177 | static void pcpu_ec_call(struct pcpu *pcpu, int ec_bit) |
| 178 | { |
| 179 | int order; |
| 180 | |
| 181 | set_bit(ec_bit, &pcpu->ec_mask); |
| 182 | order = pcpu_running(pcpu) ? |
| 183 | sigp_external_call : sigp_emergency_signal; |
| 184 | pcpu_sigp_retry(pcpu, order, 0); |
| 185 | } |
| 186 | |
| 187 | static int __cpuinit pcpu_alloc_lowcore(struct pcpu *pcpu, int cpu) |
| 188 | { |
| 189 | struct _lowcore *lc; |
| 190 | |
| 191 | if (pcpu != &pcpu_devices[0]) { |
| 192 | pcpu->lowcore = (struct _lowcore *) |
| 193 | __get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER); |
| 194 | pcpu->async_stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER); |
| 195 | pcpu->panic_stack = __get_free_page(GFP_KERNEL); |
| 196 | if (!pcpu->lowcore || !pcpu->panic_stack || !pcpu->async_stack) |
| 197 | goto out; |
Michael Holzheu | 1943f53 | 2011-10-30 15:16:38 +0100 | [diff] [blame] | 198 | } |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 199 | lc = pcpu->lowcore; |
| 200 | memcpy(lc, &S390_lowcore, 512); |
| 201 | memset((char *) lc + 512, 0, sizeof(*lc) - 512); |
| 202 | lc->async_stack = pcpu->async_stack + ASYNC_SIZE; |
| 203 | lc->panic_stack = pcpu->panic_stack + PAGE_SIZE; |
| 204 | lc->cpu_nr = cpu; |
| 205 | #ifndef CONFIG_64BIT |
| 206 | if (MACHINE_HAS_IEEE) { |
| 207 | lc->extended_save_area_addr = get_zeroed_page(GFP_KERNEL); |
| 208 | if (!lc->extended_save_area_addr) |
| 209 | goto out; |
| 210 | } |
| 211 | #else |
| 212 | if (vdso_alloc_per_cpu(lc)) |
| 213 | goto out; |
| 214 | #endif |
| 215 | lowcore_ptr[cpu] = lc; |
| 216 | pcpu_sigp_retry(pcpu, sigp_set_prefix, (u32)(unsigned long) lc); |
| 217 | return 0; |
| 218 | out: |
| 219 | if (pcpu != &pcpu_devices[0]) { |
| 220 | free_page(pcpu->panic_stack); |
| 221 | free_pages(pcpu->async_stack, ASYNC_ORDER); |
| 222 | free_pages((unsigned long) pcpu->lowcore, LC_ORDER); |
| 223 | } |
| 224 | return -ENOMEM; |
Michael Holzheu | 1943f53 | 2011-10-30 15:16:38 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 227 | static void pcpu_free_lowcore(struct pcpu *pcpu) |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 228 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 229 | pcpu_sigp_retry(pcpu, sigp_set_prefix, 0); |
| 230 | lowcore_ptr[pcpu - pcpu_devices] = NULL; |
| 231 | #ifndef CONFIG_64BIT |
| 232 | if (MACHINE_HAS_IEEE) { |
| 233 | struct _lowcore *lc = pcpu->lowcore; |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 234 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 235 | free_page((unsigned long) lc->extended_save_area_addr); |
| 236 | lc->extended_save_area_addr = 0; |
| 237 | } |
| 238 | #else |
| 239 | vdso_free_per_cpu(pcpu->lowcore); |
| 240 | #endif |
| 241 | if (pcpu != &pcpu_devices[0]) { |
| 242 | free_page(pcpu->panic_stack); |
| 243 | free_pages(pcpu->async_stack, ASYNC_ORDER); |
| 244 | free_pages((unsigned long) pcpu->lowcore, LC_ORDER); |
| 245 | } |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 246 | } |
| 247 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 248 | static void pcpu_prepare_secondary(struct pcpu *pcpu, int cpu) |
Martin Schwidefsky | 85ac7ca | 2011-12-27 11:27:22 +0100 | [diff] [blame] | 249 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 250 | struct _lowcore *lc = pcpu->lowcore; |
| 251 | |
| 252 | atomic_inc(&init_mm.context.attach_count); |
| 253 | lc->cpu_nr = cpu; |
| 254 | lc->percpu_offset = __per_cpu_offset[cpu]; |
| 255 | lc->kernel_asce = S390_lowcore.kernel_asce; |
| 256 | lc->machine_flags = S390_lowcore.machine_flags; |
| 257 | lc->ftrace_func = S390_lowcore.ftrace_func; |
| 258 | lc->user_timer = lc->system_timer = lc->steal_timer = 0; |
| 259 | __ctl_store(lc->cregs_save_area, 0, 15); |
| 260 | save_access_regs((unsigned int *) lc->access_regs_save_area); |
| 261 | memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list, |
| 262 | MAX_FACILITY_BIT/8); |
Martin Schwidefsky | 85ac7ca | 2011-12-27 11:27:22 +0100 | [diff] [blame] | 263 | } |
| 264 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 265 | static void pcpu_attach_task(struct pcpu *pcpu, struct task_struct *tsk) |
| 266 | { |
| 267 | struct _lowcore *lc = pcpu->lowcore; |
| 268 | struct thread_info *ti = task_thread_info(tsk); |
| 269 | |
| 270 | lc->kernel_stack = (unsigned long) task_stack_page(tsk) + THREAD_SIZE; |
| 271 | lc->thread_info = (unsigned long) task_thread_info(tsk); |
| 272 | lc->current_task = (unsigned long) tsk; |
| 273 | lc->user_timer = ti->user_timer; |
| 274 | lc->system_timer = ti->system_timer; |
| 275 | lc->steal_timer = 0; |
| 276 | } |
| 277 | |
| 278 | static void pcpu_start_fn(struct pcpu *pcpu, void (*func)(void *), void *data) |
| 279 | { |
| 280 | struct _lowcore *lc = pcpu->lowcore; |
| 281 | |
| 282 | lc->restart_stack = lc->kernel_stack; |
| 283 | lc->restart_fn = (unsigned long) func; |
| 284 | lc->restart_data = (unsigned long) data; |
| 285 | lc->restart_source = -1UL; |
| 286 | pcpu_sigp_retry(pcpu, sigp_restart, 0); |
| 287 | } |
| 288 | |
| 289 | /* |
| 290 | * Call function via PSW restart on pcpu and stop the current cpu. |
| 291 | */ |
| 292 | static void pcpu_delegate(struct pcpu *pcpu, void (*func)(void *), |
| 293 | void *data, unsigned long stack) |
| 294 | { |
| 295 | struct _lowcore *lc = pcpu->lowcore; |
| 296 | unsigned short this_cpu; |
| 297 | |
| 298 | __load_psw_mask(psw_kernel_bits); |
| 299 | this_cpu = stap(); |
| 300 | if (pcpu->address == this_cpu) |
| 301 | func(data); /* should not return */ |
| 302 | /* Stop target cpu (if func returns this stops the current cpu). */ |
| 303 | pcpu_sigp_retry(pcpu, sigp_stop, 0); |
| 304 | /* Restart func on the target cpu and stop the current cpu. */ |
| 305 | lc->restart_stack = stack; |
| 306 | lc->restart_fn = (unsigned long) func; |
| 307 | lc->restart_data = (unsigned long) data; |
| 308 | lc->restart_source = (unsigned long) this_cpu; |
| 309 | asm volatile( |
| 310 | "0: sigp 0,%0,6 # sigp restart to target cpu\n" |
| 311 | " brc 2,0b # busy, try again\n" |
| 312 | "1: sigp 0,%1,5 # sigp stop to current cpu\n" |
| 313 | " brc 2,1b # busy, try again\n" |
| 314 | : : "d" (pcpu->address), "d" (this_cpu) : "0", "1", "cc"); |
| 315 | for (;;) ; |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * Call function on an online CPU. |
| 320 | */ |
| 321 | void smp_call_online_cpu(void (*func)(void *), void *data) |
| 322 | { |
| 323 | struct pcpu *pcpu; |
| 324 | |
| 325 | /* Use the current cpu if it is online. */ |
| 326 | pcpu = pcpu_find_address(cpu_online_mask, stap()); |
| 327 | if (!pcpu) |
| 328 | /* Use the first online cpu. */ |
| 329 | pcpu = pcpu_devices + cpumask_first(cpu_online_mask); |
| 330 | pcpu_delegate(pcpu, func, data, (unsigned long) restart_stack); |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Call function on the ipl CPU. |
| 335 | */ |
| 336 | void smp_call_ipl_cpu(void (*func)(void *), void *data) |
| 337 | { |
| 338 | pcpu_delegate(&pcpu_devices[0], func, data, pcpu_devices->panic_stack); |
| 339 | } |
| 340 | |
| 341 | int smp_find_processor_id(u16 address) |
| 342 | { |
| 343 | int cpu; |
| 344 | |
| 345 | for_each_present_cpu(cpu) |
| 346 | if (pcpu_devices[cpu].address == address) |
| 347 | return cpu; |
| 348 | return -1; |
| 349 | } |
| 350 | |
| 351 | int smp_vcpu_scheduled(int cpu) |
| 352 | { |
| 353 | return pcpu_running(pcpu_devices + cpu); |
| 354 | } |
| 355 | |
| 356 | void smp_yield(void) |
| 357 | { |
| 358 | if (MACHINE_HAS_DIAG44) |
| 359 | asm volatile("diag 0,0,0x44"); |
| 360 | } |
| 361 | |
| 362 | void smp_yield_cpu(int cpu) |
| 363 | { |
| 364 | if (MACHINE_HAS_DIAG9C) |
| 365 | asm volatile("diag %0,0,0x9c" |
| 366 | : : "d" (pcpu_devices[cpu].address)); |
| 367 | else if (MACHINE_HAS_DIAG44) |
| 368 | asm volatile("diag 0,0,0x44"); |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | * Send cpus emergency shutdown signal. This gives the cpus the |
| 373 | * opportunity to complete outstanding interrupts. |
| 374 | */ |
| 375 | void smp_emergency_stop(cpumask_t *cpumask) |
| 376 | { |
| 377 | u64 end; |
| 378 | int cpu; |
| 379 | |
| 380 | end = get_clock() + (1000000UL << 12); |
| 381 | for_each_cpu(cpu, cpumask) { |
| 382 | struct pcpu *pcpu = pcpu_devices + cpu; |
| 383 | set_bit(ec_stop_cpu, &pcpu->ec_mask); |
| 384 | while (__pcpu_sigp(pcpu->address, sigp_emergency_signal, |
| 385 | 0, NULL) == sigp_busy && |
| 386 | get_clock() < end) |
| 387 | cpu_relax(); |
| 388 | } |
| 389 | while (get_clock() < end) { |
| 390 | for_each_cpu(cpu, cpumask) |
| 391 | if (pcpu_stopped(pcpu_devices + cpu)) |
| 392 | cpumask_clear_cpu(cpu, cpumask); |
| 393 | if (cpumask_empty(cpumask)) |
| 394 | break; |
| 395 | cpu_relax(); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * Stop all cpus but the current one. |
| 401 | */ |
Heiko Carstens | 677d762 | 2007-11-20 11:13:37 +0100 | [diff] [blame] | 402 | void smp_send_stop(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | { |
Martin Schwidefsky | 85ac7ca | 2011-12-27 11:27:22 +0100 | [diff] [blame] | 404 | cpumask_t cpumask; |
| 405 | int cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Heiko Carstens | 677d762 | 2007-11-20 11:13:37 +0100 | [diff] [blame] | 407 | /* Disable all interrupts/machine checks */ |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 408 | __load_psw_mask(psw_kernel_bits | PSW_MASK_DAT); |
Christian Borntraeger | 3324e60 | 2009-03-26 15:23:56 +0100 | [diff] [blame] | 409 | trace_hardirqs_off(); |
Heiko Carstens | 677d762 | 2007-11-20 11:13:37 +0100 | [diff] [blame] | 410 | |
Michael Holzheu | 3ab121a | 2012-03-11 11:59:32 -0400 | [diff] [blame] | 411 | debug_set_critical(); |
Martin Schwidefsky | 85ac7ca | 2011-12-27 11:27:22 +0100 | [diff] [blame] | 412 | cpumask_copy(&cpumask, cpu_online_mask); |
| 413 | cpumask_clear_cpu(smp_processor_id(), &cpumask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 415 | if (oops_in_progress) |
| 416 | smp_emergency_stop(&cpumask); |
Martin Schwidefsky | 85ac7ca | 2011-12-27 11:27:22 +0100 | [diff] [blame] | 417 | |
| 418 | /* stop all processors */ |
| 419 | for_each_cpu(cpu, &cpumask) { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 420 | struct pcpu *pcpu = pcpu_devices + cpu; |
| 421 | pcpu_sigp_retry(pcpu, sigp_stop, 0); |
| 422 | while (!pcpu_stopped(pcpu)) |
Heiko Carstens | c6b5b84 | 2006-12-04 15:40:33 +0100 | [diff] [blame] | 423 | cpu_relax(); |
| 424 | } |
| 425 | } |
| 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | /* |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 428 | * Stop the current cpu. |
| 429 | */ |
| 430 | void smp_stop_cpu(void) |
| 431 | { |
| 432 | pcpu_sigp_retry(pcpu_devices + smp_processor_id(), sigp_stop, 0); |
| 433 | for (;;) ; |
| 434 | } |
| 435 | |
| 436 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | * This is the main routine where commands issued by other |
| 438 | * cpus are handled. |
| 439 | */ |
Heiko Carstens | fde15c3 | 2012-03-11 11:59:31 -0400 | [diff] [blame] | 440 | static void do_ext_call_interrupt(struct ext_code ext_code, |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 441 | unsigned int param32, unsigned long param64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 443 | unsigned long bits; |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 444 | int cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 446 | cpu = smp_processor_id(); |
Heiko Carstens | fde15c3 | 2012-03-11 11:59:31 -0400 | [diff] [blame] | 447 | if (ext_code.code == 0x1202) |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 448 | kstat_cpu(cpu).irqs[EXTINT_EXC]++; |
Heiko Carstens | 2a3a2d6 | 2011-10-30 15:17:19 +0100 | [diff] [blame] | 449 | else |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 450 | kstat_cpu(cpu).irqs[EXTINT_EMS]++; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 451 | /* |
| 452 | * handle bit signal external calls |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 453 | */ |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 454 | bits = xchg(&pcpu_devices[cpu].ec_mask, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Martin Schwidefsky | 85ac7ca | 2011-12-27 11:27:22 +0100 | [diff] [blame] | 456 | if (test_bit(ec_stop_cpu, &bits)) |
| 457 | smp_stop_cpu(); |
| 458 | |
Peter Zijlstra | 184748c | 2011-04-05 17:23:39 +0200 | [diff] [blame] | 459 | if (test_bit(ec_schedule, &bits)) |
| 460 | scheduler_ipi(); |
| 461 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 462 | if (test_bit(ec_call_function, &bits)) |
Heiko Carstens | ca9fc75 | 2008-12-25 13:38:39 +0100 | [diff] [blame] | 463 | generic_smp_call_function_interrupt(); |
| 464 | |
| 465 | if (test_bit(ec_call_function_single, &bits)) |
| 466 | generic_smp_call_function_single_interrupt(); |
Martin Schwidefsky | 85ac7ca | 2011-12-27 11:27:22 +0100 | [diff] [blame] | 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Rusty Russell | 630cd04 | 2009-09-24 09:34:45 -0600 | [diff] [blame] | 470 | void arch_send_call_function_ipi_mask(const struct cpumask *mask) |
Heiko Carstens | ca9fc75 | 2008-12-25 13:38:39 +0100 | [diff] [blame] | 471 | { |
| 472 | int cpu; |
| 473 | |
Rusty Russell | 630cd04 | 2009-09-24 09:34:45 -0600 | [diff] [blame] | 474 | for_each_cpu(cpu, mask) |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 475 | pcpu_ec_call(pcpu_devices + cpu, ec_call_function); |
Heiko Carstens | ca9fc75 | 2008-12-25 13:38:39 +0100 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | void arch_send_call_function_single_ipi(int cpu) |
| 479 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 480 | pcpu_ec_call(pcpu_devices + cpu, ec_call_function_single); |
Heiko Carstens | ca9fc75 | 2008-12-25 13:38:39 +0100 | [diff] [blame] | 481 | } |
| 482 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 483 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | /* |
| 485 | * this function sends a 'purge tlb' signal to another CPU. |
| 486 | */ |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 487 | static void smp_ptlb_callback(void *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
Martin Schwidefsky | ba8a922 | 2007-10-22 12:52:44 +0200 | [diff] [blame] | 489 | __tlb_flush_local(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | void smp_ptlb_all(void) |
| 493 | { |
Jens Axboe | 15c8b6c | 2008-05-09 09:39:44 +0200 | [diff] [blame] | 494 | on_each_cpu(smp_ptlb_callback, NULL, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | EXPORT_SYMBOL(smp_ptlb_all); |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 497 | #endif /* ! CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
| 499 | /* |
| 500 | * this function sends a 'reschedule' IPI to another CPU. |
| 501 | * it goes straight through and wastes no time serializing |
| 502 | * anything. Worst case is that we lose a reschedule ... |
| 503 | */ |
| 504 | void smp_send_reschedule(int cpu) |
| 505 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 506 | pcpu_ec_call(pcpu_devices + cpu, ec_schedule); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /* |
| 510 | * parameter area for the set/clear control bit callbacks |
| 511 | */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 512 | struct ec_creg_mask_parms { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 513 | unsigned long orval; |
| 514 | unsigned long andval; |
| 515 | int cr; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 516 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
| 518 | /* |
| 519 | * callback for setting/clearing control bits |
| 520 | */ |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 521 | static void smp_ctl_bit_callback(void *info) |
| 522 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 523 | struct ec_creg_mask_parms *pp = info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | unsigned long cregs[16]; |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 525 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 526 | __ctl_store(cregs, 0, 15); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 527 | cregs[pp->cr] = (cregs[pp->cr] & pp->andval) | pp->orval; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 528 | __ctl_load(cregs, 0, 15); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /* |
| 532 | * Set a bit in a control register of all cpus |
| 533 | */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 534 | void smp_ctl_set_bit(int cr, int bit) |
| 535 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 536 | struct ec_creg_mask_parms parms = { 1UL << bit, -1UL, cr }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
Jens Axboe | 15c8b6c | 2008-05-09 09:39:44 +0200 | [diff] [blame] | 538 | on_each_cpu(smp_ctl_bit_callback, &parms, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 540 | EXPORT_SYMBOL(smp_ctl_set_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
| 542 | /* |
| 543 | * Clear a bit in a control register of all cpus |
| 544 | */ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 545 | void smp_ctl_clear_bit(int cr, int bit) |
| 546 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 547 | struct ec_creg_mask_parms parms = { 0, ~(1UL << bit), cr }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
Jens Axboe | 15c8b6c | 2008-05-09 09:39:44 +0200 | [diff] [blame] | 549 | on_each_cpu(smp_ctl_bit_callback, &parms, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | } |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 551 | EXPORT_SYMBOL(smp_ctl_clear_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 553 | #if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_CRASH_DUMP) |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 554 | |
Heiko Carstens | f64ca21 | 2010-02-26 22:37:32 +0100 | [diff] [blame] | 555 | struct save_area *zfcpdump_save_areas[NR_CPUS + 1]; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 556 | EXPORT_SYMBOL_GPL(zfcpdump_save_areas); |
| 557 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 558 | static void __init smp_get_save_area(int cpu, u16 address) |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 559 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 560 | void *lc = pcpu_devices[0].lowcore; |
| 561 | struct save_area *save_area; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 562 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 563 | if (is_kdump_kernel()) |
| 564 | return; |
| 565 | if (!OLDMEM_BASE && (address == boot_cpu_address || |
| 566 | ipl_info.type != IPL_TYPE_FCP_DUMP)) |
| 567 | return; |
| 568 | if (cpu >= NR_CPUS) { |
| 569 | pr_warning("CPU %i exceeds the maximum %i and is excluded " |
| 570 | "from the dump\n", cpu, NR_CPUS - 1); |
| 571 | return; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 572 | } |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 573 | save_area = kmalloc(sizeof(struct save_area), GFP_KERNEL); |
| 574 | if (!save_area) |
| 575 | panic("could not allocate memory for save area\n"); |
| 576 | zfcpdump_save_areas[cpu] = save_area; |
| 577 | #ifdef CONFIG_CRASH_DUMP |
| 578 | if (address == boot_cpu_address) { |
| 579 | /* Copy the registers of the boot cpu. */ |
| 580 | copy_oldmem_page(1, (void *) save_area, sizeof(*save_area), |
| 581 | SAVE_AREA_BASE - PAGE_SIZE, 0); |
| 582 | return; |
| 583 | } |
| 584 | #endif |
| 585 | /* Get the registers of a non-boot cpu. */ |
| 586 | __pcpu_sigp_relax(address, sigp_stop_and_store_status, 0, NULL); |
| 587 | memcpy_real(save_area, lc + SAVE_AREA_BASE, sizeof(*save_area)); |
| 588 | } |
| 589 | |
| 590 | int smp_store_status(int cpu) |
| 591 | { |
| 592 | struct pcpu *pcpu; |
| 593 | |
| 594 | pcpu = pcpu_devices + cpu; |
| 595 | if (__pcpu_sigp_relax(pcpu->address, sigp_stop_and_store_status, |
| 596 | 0, NULL) != sigp_order_code_accepted) |
| 597 | return -EIO; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 598 | return 0; |
| 599 | } |
| 600 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 601 | #else /* CONFIG_ZFCPDUMP || CONFIG_CRASH_DUMP */ |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 602 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 603 | static inline void smp_get_save_area(int cpu, u16 address) { } |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 604 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 605 | #endif /* CONFIG_ZFCPDUMP || CONFIG_CRASH_DUMP */ |
| 606 | |
| 607 | static struct sclp_cpu_info *smp_get_cpu_info(void) |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 608 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 609 | static int use_sigp_detection; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 610 | struct sclp_cpu_info *info; |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 611 | int address; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 612 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 613 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 614 | if (info && (use_sigp_detection || sclp_get_cpu_info(info))) { |
| 615 | use_sigp_detection = 1; |
| 616 | for (address = 0; address <= MAX_CPU_ADDRESS; address++) { |
| 617 | if (__pcpu_sigp_relax(address, sigp_sense, 0, NULL) == |
| 618 | sigp_not_operational) |
| 619 | continue; |
| 620 | info->cpu[info->configured].address = address; |
| 621 | info->configured++; |
| 622 | } |
| 623 | info->combined = info->configured; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 624 | } |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 625 | return info; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 626 | } |
| 627 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 628 | static int __devinit smp_add_present_cpu(int cpu); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 629 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 630 | static int __devinit __smp_rescan_cpus(struct sclp_cpu_info *info, |
| 631 | int sysfs_add) |
| 632 | { |
| 633 | struct pcpu *pcpu; |
| 634 | cpumask_t avail; |
| 635 | int cpu, nr, i; |
| 636 | |
| 637 | nr = 0; |
KOSAKI Motohiro | 0f1959f | 2011-05-23 10:24:36 +0200 | [diff] [blame] | 638 | cpumask_xor(&avail, cpu_possible_mask, cpu_present_mask); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 639 | cpu = cpumask_first(&avail); |
| 640 | for (i = 0; (i < info->combined) && (cpu < nr_cpu_ids); i++) { |
| 641 | if (info->has_cpu_type && info->cpu[i].type != boot_cpu_type) |
| 642 | continue; |
| 643 | if (pcpu_find_address(cpu_present_mask, info->cpu[i].address)) |
| 644 | continue; |
| 645 | pcpu = pcpu_devices + cpu; |
| 646 | pcpu->address = info->cpu[i].address; |
| 647 | pcpu->state = (cpu >= info->configured) ? |
| 648 | CPU_STATE_STANDBY : CPU_STATE_CONFIGURED; |
| 649 | cpu_set_polarization(cpu, POLARIZATION_UNKNOWN); |
| 650 | set_cpu_present(cpu, true); |
| 651 | if (sysfs_add && smp_add_present_cpu(cpu) != 0) |
| 652 | set_cpu_present(cpu, false); |
| 653 | else |
| 654 | nr++; |
| 655 | cpu = cpumask_next(cpu, &avail); |
| 656 | } |
| 657 | return nr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 660 | static void __init smp_detect_cpus(void) |
| 661 | { |
| 662 | unsigned int cpu, c_cpus, s_cpus; |
| 663 | struct sclp_cpu_info *info; |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 664 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 665 | info = smp_get_cpu_info(); |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 666 | if (!info) |
| 667 | panic("smp_detect_cpus failed to allocate memory\n"); |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 668 | if (info->has_cpu_type) { |
| 669 | for (cpu = 0; cpu < info->combined; cpu++) { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 670 | if (info->cpu[cpu].address != boot_cpu_address) |
| 671 | continue; |
| 672 | /* The boot cpu dictates the cpu type. */ |
| 673 | boot_cpu_type = info->cpu[cpu].type; |
| 674 | break; |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 675 | } |
| 676 | } |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 677 | c_cpus = s_cpus = 0; |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 678 | for (cpu = 0; cpu < info->combined; cpu++) { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 679 | if (info->has_cpu_type && info->cpu[cpu].type != boot_cpu_type) |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 680 | continue; |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 681 | if (cpu < info->configured) { |
| 682 | smp_get_save_area(c_cpus, info->cpu[cpu].address); |
| 683 | c_cpus++; |
| 684 | } else |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 685 | s_cpus++; |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 686 | } |
Martin Schwidefsky | 395d31d | 2008-12-25 13:39:50 +0100 | [diff] [blame] | 687 | pr_info("%d configured CPUs, %d standby CPUs\n", c_cpus, s_cpus); |
Martin Schwidefsky | 9d40d2e | 2008-01-26 14:11:31 +0100 | [diff] [blame] | 688 | get_online_cpus(); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 689 | __smp_rescan_cpus(info, 0); |
Martin Schwidefsky | 9d40d2e | 2008-01-26 14:11:31 +0100 | [diff] [blame] | 690 | put_online_cpus(); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 691 | kfree(info); |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 692 | } |
| 693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | /* |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 695 | * Activate a secondary processor. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | */ |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 697 | static void __cpuinit smp_start_secondary(void *cpuvoid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 699 | S390_lowcore.last_update_clock = get_clock(); |
| 700 | S390_lowcore.restart_stack = (unsigned long) restart_stack; |
| 701 | S390_lowcore.restart_fn = (unsigned long) do_restart; |
| 702 | S390_lowcore.restart_data = 0; |
| 703 | S390_lowcore.restart_source = -1UL; |
| 704 | restore_access_regs(S390_lowcore.access_regs_save_area); |
| 705 | __ctl_load(S390_lowcore.cregs_save_area, 0, 15); |
| 706 | __load_psw_mask(psw_kernel_bits | PSW_MASK_DAT); |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 707 | cpu_init(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 708 | preempt_disable(); |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 709 | init_cpu_timer(); |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 710 | init_cpu_vtimer(); |
Heiko Carstens | 29b08d2 | 2006-12-04 15:40:40 +0100 | [diff] [blame] | 711 | pfault_init(); |
Manfred Spraul | e545a61 | 2008-09-07 16:57:22 +0200 | [diff] [blame] | 712 | notify_cpu_starting(smp_processor_id()); |
Heiko Carstens | ca9fc75 | 2008-12-25 13:38:39 +0100 | [diff] [blame] | 713 | ipi_call_lock(); |
KOSAKI Motohiro | 0f1959f | 2011-05-23 10:24:36 +0200 | [diff] [blame] | 714 | set_cpu_online(smp_processor_id(), true); |
Heiko Carstens | ca9fc75 | 2008-12-25 13:38:39 +0100 | [diff] [blame] | 715 | ipi_call_unlock(); |
Heiko Carstens | cc34321 | 2011-08-03 16:44:27 +0200 | [diff] [blame] | 716 | /* |
| 717 | * Wait until the cpu which brought this one up marked it |
| 718 | * active before enabling interrupts. |
| 719 | */ |
| 720 | while (!cpumask_test_cpu(smp_processor_id(), cpu_active_mask)) |
| 721 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | local_irq_enable(); |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 723 | /* cpu_idle will call schedule for us */ |
| 724 | cpu_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Heiko Carstens | f230886 | 2011-01-05 12:48:08 +0100 | [diff] [blame] | 727 | struct create_idle { |
| 728 | struct work_struct work; |
| 729 | struct task_struct *idle; |
| 730 | struct completion done; |
| 731 | int cpu; |
| 732 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Heiko Carstens | f230886 | 2011-01-05 12:48:08 +0100 | [diff] [blame] | 734 | static void __cpuinit smp_fork_idle(struct work_struct *work) |
| 735 | { |
| 736 | struct create_idle *c_idle; |
| 737 | |
| 738 | c_idle = container_of(work, struct create_idle, work); |
| 739 | c_idle->idle = fork_idle(c_idle->cpu); |
| 740 | complete(&c_idle->done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
| 742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | /* Upping and downing of CPUs */ |
Heiko Carstens | 1cb6bb4 | 2008-01-26 14:11:14 +0100 | [diff] [blame] | 744 | int __cpuinit __cpu_up(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | { |
Heiko Carstens | f230886 | 2011-01-05 12:48:08 +0100 | [diff] [blame] | 746 | struct create_idle c_idle; |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 747 | struct pcpu *pcpu; |
| 748 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 750 | pcpu = pcpu_devices + cpu; |
| 751 | if (pcpu->state != CPU_STATE_CONFIGURED) |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 752 | return -EIO; |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 753 | if (pcpu_sigp_retry(pcpu, sigp_initial_cpu_reset, 0) != |
| 754 | sigp_order_code_accepted) |
| 755 | return -EIO; |
| 756 | if (!pcpu->idle) { |
Heiko Carstens | f230886 | 2011-01-05 12:48:08 +0100 | [diff] [blame] | 757 | c_idle.done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done); |
| 758 | INIT_WORK_ONSTACK(&c_idle.work, smp_fork_idle); |
| 759 | c_idle.cpu = cpu; |
| 760 | schedule_work(&c_idle.work); |
| 761 | wait_for_completion(&c_idle.done); |
| 762 | if (IS_ERR(c_idle.idle)) |
| 763 | return PTR_ERR(c_idle.idle); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 764 | pcpu->idle = c_idle.idle; |
Heiko Carstens | f230886 | 2011-01-05 12:48:08 +0100 | [diff] [blame] | 765 | } |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 766 | init_idle(pcpu->idle, cpu); |
| 767 | rc = pcpu_alloc_lowcore(pcpu, cpu); |
| 768 | if (rc) |
| 769 | return rc; |
| 770 | pcpu_prepare_secondary(pcpu, cpu); |
| 771 | pcpu_attach_task(pcpu, pcpu->idle); |
| 772 | pcpu_start_fn(pcpu, smp_start_secondary, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | while (!cpu_online(cpu)) |
| 774 | cpu_relax(); |
| 775 | return 0; |
| 776 | } |
| 777 | |
Heiko Carstens | 37a3302 | 2006-02-17 13:52:47 -0800 | [diff] [blame] | 778 | static int __init setup_possible_cpus(char *s) |
| 779 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 780 | int max, cpu; |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 781 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 782 | if (kstrtoint(s, 0, &max) < 0) |
| 783 | return 0; |
Heiko Carstens | 88e0128 | 2009-04-14 15:36:25 +0200 | [diff] [blame] | 784 | init_cpu_possible(cpumask_of(0)); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 785 | for (cpu = 1; cpu < max && cpu < nr_cpu_ids; cpu++) |
Rusty Russell | def6cfb | 2009-03-26 15:25:00 +0100 | [diff] [blame] | 786 | set_cpu_possible(cpu, true); |
Heiko Carstens | 37a3302 | 2006-02-17 13:52:47 -0800 | [diff] [blame] | 787 | return 0; |
| 788 | } |
| 789 | early_param("possible_cpus", setup_possible_cpus); |
| 790 | |
Heiko Carstens | 48483b3 | 2008-01-26 14:11:05 +0100 | [diff] [blame] | 791 | #ifdef CONFIG_HOTPLUG_CPU |
| 792 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 793 | int __cpu_disable(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 795 | unsigned long cregs[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 797 | set_cpu_online(smp_processor_id(), false); |
| 798 | /* Disable pseudo page faults on this cpu. */ |
Heiko Carstens | 29b08d2 | 2006-12-04 15:40:40 +0100 | [diff] [blame] | 799 | pfault_fini(); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 800 | /* Disable interrupt sources via control register. */ |
| 801 | __ctl_store(cregs, 0, 15); |
| 802 | cregs[0] &= ~0x0000ee70UL; /* disable all external interrupts */ |
| 803 | cregs[6] &= ~0xff000000UL; /* disable all I/O interrupts */ |
| 804 | cregs[14] &= ~0x1f000000UL; /* disable most machine checks */ |
| 805 | __ctl_load(cregs, 0, 15); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | return 0; |
| 807 | } |
| 808 | |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 809 | void __cpu_die(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 811 | struct pcpu *pcpu; |
| 812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | /* Wait until target cpu is down */ |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 814 | pcpu = pcpu_devices + cpu; |
| 815 | while (!pcpu_stopped(pcpu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | cpu_relax(); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 817 | pcpu_free_lowcore(pcpu); |
Martin Schwidefsky | 050eef3 | 2010-08-24 09:26:21 +0200 | [diff] [blame] | 818 | atomic_dec(&init_mm.context.attach_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } |
| 820 | |
Heiko Carstens | b456d94 | 2011-05-23 10:24:33 +0200 | [diff] [blame] | 821 | void __noreturn cpu_die(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
| 823 | idle_task_exit(); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 824 | pcpu_sigp_retry(pcpu_devices + smp_processor_id(), sigp_stop, 0); |
| 825 | for (;;) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Heiko Carstens | 255acee | 2006-02-17 13:52:46 -0800 | [diff] [blame] | 828 | #endif /* CONFIG_HOTPLUG_CPU */ |
| 829 | |
Michael Holzheu | 4857d4b | 2012-03-11 11:59:34 -0400 | [diff] [blame^] | 830 | static void smp_call_os_info_init_fn(void) |
| 831 | { |
| 832 | int (*init_fn)(void); |
| 833 | unsigned long size; |
| 834 | |
| 835 | init_fn = os_info_old_entry(OS_INFO_INIT_FN, &size); |
| 836 | if (!init_fn) |
| 837 | return; |
| 838 | init_fn(); |
| 839 | } |
| 840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | void __init smp_prepare_cpus(unsigned int max_cpus) |
| 842 | { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 843 | /* request the 0x1201 emergency signal external interrupt */ |
| 844 | if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0) |
| 845 | panic("Couldn't request external interrupt 0x1201"); |
Martin Schwidefsky | d98e19c | 2011-10-30 15:16:58 +0100 | [diff] [blame] | 846 | /* request the 0x1202 external call external interrupt */ |
| 847 | if (register_external_interrupt(0x1202, do_ext_call_interrupt) != 0) |
| 848 | panic("Couldn't request external interrupt 0x1202"); |
Michael Holzheu | 4857d4b | 2012-03-11 11:59:34 -0400 | [diff] [blame^] | 849 | smp_call_os_info_init_fn(); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 850 | smp_detect_cpus(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Heiko Carstens | ea1f4ee | 2007-05-31 17:38:05 +0200 | [diff] [blame] | 853 | void __init smp_prepare_boot_cpu(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 855 | struct pcpu *pcpu = pcpu_devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 857 | boot_cpu_address = stap(); |
| 858 | pcpu->idle = current; |
| 859 | pcpu->state = CPU_STATE_CONFIGURED; |
| 860 | pcpu->address = boot_cpu_address; |
| 861 | pcpu->lowcore = (struct _lowcore *)(unsigned long) store_prefix(); |
| 862 | pcpu->async_stack = S390_lowcore.async_stack - ASYNC_SIZE; |
| 863 | pcpu->panic_stack = S390_lowcore.panic_stack - PAGE_SIZE; |
| 864 | S390_lowcore.percpu_offset = __per_cpu_offset[0]; |
| 865 | cpu_set_polarization(0, POLARIZATION_UNKNOWN); |
KOSAKI Motohiro | 0f1959f | 2011-05-23 10:24:36 +0200 | [diff] [blame] | 866 | set_cpu_present(0, true); |
| 867 | set_cpu_online(0, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Heiko Carstens | ea1f4ee | 2007-05-31 17:38:05 +0200 | [diff] [blame] | 870 | void __init smp_cpus_done(unsigned int max_cpus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Heiko Carstens | 02beacc | 2010-01-13 20:44:34 +0100 | [diff] [blame] | 874 | void __init smp_setup_processor_id(void) |
| 875 | { |
| 876 | S390_lowcore.cpu_nr = 0; |
Heiko Carstens | 02beacc | 2010-01-13 20:44:34 +0100 | [diff] [blame] | 877 | } |
| 878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | /* |
| 880 | * the frequency of the profiling timer can be changed |
| 881 | * by writing a multiplier value into /proc/profile. |
| 882 | * |
| 883 | * usually you want to run this on all CPUs ;) |
| 884 | */ |
| 885 | int setup_profiling_timer(unsigned int multiplier) |
| 886 | { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 887 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | } |
| 889 | |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 890 | #ifdef CONFIG_HOTPLUG_CPU |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 891 | static ssize_t cpu_configure_show(struct device *dev, |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 892 | struct device_attribute *attr, char *buf) |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 893 | { |
| 894 | ssize_t count; |
| 895 | |
| 896 | mutex_lock(&smp_cpu_state_mutex); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 897 | count = sprintf(buf, "%d\n", pcpu_devices[dev->id].state); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 898 | mutex_unlock(&smp_cpu_state_mutex); |
| 899 | return count; |
| 900 | } |
| 901 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 902 | static ssize_t cpu_configure_store(struct device *dev, |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 903 | struct device_attribute *attr, |
| 904 | const char *buf, size_t count) |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 905 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 906 | struct pcpu *pcpu; |
| 907 | int cpu, val, rc; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 908 | char delim; |
| 909 | |
| 910 | if (sscanf(buf, "%d %c", &val, &delim) != 1) |
| 911 | return -EINVAL; |
| 912 | if (val != 0 && val != 1) |
| 913 | return -EINVAL; |
Martin Schwidefsky | 9d40d2e | 2008-01-26 14:11:31 +0100 | [diff] [blame] | 914 | get_online_cpus(); |
Heiko Carstens | 0b18d31 | 2008-04-30 13:38:36 +0200 | [diff] [blame] | 915 | mutex_lock(&smp_cpu_state_mutex); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 916 | rc = -EBUSY; |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 917 | /* disallow configuration changes of online cpus and cpu 0 */ |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 918 | cpu = dev->id; |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 919 | if (cpu_online(cpu) || cpu == 0) |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 920 | goto out; |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 921 | pcpu = pcpu_devices + cpu; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 922 | rc = 0; |
| 923 | switch (val) { |
| 924 | case 0: |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 925 | if (pcpu->state != CPU_STATE_CONFIGURED) |
| 926 | break; |
| 927 | rc = sclp_cpu_deconfigure(pcpu->address); |
| 928 | if (rc) |
| 929 | break; |
| 930 | pcpu->state = CPU_STATE_STANDBY; |
| 931 | cpu_set_polarization(cpu, POLARIZATION_UNKNOWN); |
| 932 | topology_expect_change(); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 933 | break; |
| 934 | case 1: |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 935 | if (pcpu->state != CPU_STATE_STANDBY) |
| 936 | break; |
| 937 | rc = sclp_cpu_configure(pcpu->address); |
| 938 | if (rc) |
| 939 | break; |
| 940 | pcpu->state = CPU_STATE_CONFIGURED; |
| 941 | cpu_set_polarization(cpu, POLARIZATION_UNKNOWN); |
| 942 | topology_expect_change(); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 943 | break; |
| 944 | default: |
| 945 | break; |
| 946 | } |
| 947 | out: |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 948 | mutex_unlock(&smp_cpu_state_mutex); |
Heiko Carstens | 0b18d31 | 2008-04-30 13:38:36 +0200 | [diff] [blame] | 949 | put_online_cpus(); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 950 | return rc ? rc : count; |
| 951 | } |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 952 | static DEVICE_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 953 | #endif /* CONFIG_HOTPLUG_CPU */ |
| 954 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 955 | static ssize_t show_cpu_address(struct device *dev, |
| 956 | struct device_attribute *attr, char *buf) |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 957 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 958 | return sprintf(buf, "%d\n", pcpu_devices[dev->id].address); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 959 | } |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 960 | static DEVICE_ATTR(address, 0444, show_cpu_address, NULL); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 961 | |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 962 | static struct attribute *cpu_common_attrs[] = { |
| 963 | #ifdef CONFIG_HOTPLUG_CPU |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 964 | &dev_attr_configure.attr, |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 965 | #endif |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 966 | &dev_attr_address.attr, |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 967 | NULL, |
| 968 | }; |
| 969 | |
| 970 | static struct attribute_group cpu_common_attr_group = { |
| 971 | .attrs = cpu_common_attrs, |
| 972 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 974 | static ssize_t show_capability(struct device *dev, |
| 975 | struct device_attribute *attr, char *buf) |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 976 | { |
| 977 | unsigned int capability; |
| 978 | int rc; |
| 979 | |
| 980 | rc = get_cpu_capability(&capability); |
| 981 | if (rc) |
| 982 | return rc; |
| 983 | return sprintf(buf, "%u\n", capability); |
| 984 | } |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 985 | static DEVICE_ATTR(capability, 0444, show_capability, NULL); |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 986 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 987 | static ssize_t show_idle_count(struct device *dev, |
| 988 | struct device_attribute *attr, char *buf) |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 989 | { |
Martin Schwidefsky | 4c1051e | 2012-03-11 11:59:27 -0400 | [diff] [blame] | 990 | struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id); |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 991 | unsigned long long idle_count; |
Martin Schwidefsky | e98bbaa | 2009-06-22 12:08:20 +0200 | [diff] [blame] | 992 | unsigned int sequence; |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 993 | |
Martin Schwidefsky | 4c1051e | 2012-03-11 11:59:27 -0400 | [diff] [blame] | 994 | do { |
| 995 | sequence = ACCESS_ONCE(idle->sequence); |
| 996 | idle_count = ACCESS_ONCE(idle->idle_count); |
| 997 | if (ACCESS_ONCE(idle->idle_enter)) |
| 998 | idle_count++; |
| 999 | } while ((sequence & 1) || (idle->sequence != sequence)); |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 1000 | return sprintf(buf, "%llu\n", idle_count); |
| 1001 | } |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1002 | static DEVICE_ATTR(idle_count, 0444, show_idle_count, NULL); |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 1003 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1004 | static ssize_t show_idle_time(struct device *dev, |
| 1005 | struct device_attribute *attr, char *buf) |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 1006 | { |
Martin Schwidefsky | 4c1051e | 2012-03-11 11:59:27 -0400 | [diff] [blame] | 1007 | struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id); |
| 1008 | unsigned long long now, idle_time, idle_enter, idle_exit; |
Martin Schwidefsky | e98bbaa | 2009-06-22 12:08:20 +0200 | [diff] [blame] | 1009 | unsigned int sequence; |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 1010 | |
Martin Schwidefsky | 4c1051e | 2012-03-11 11:59:27 -0400 | [diff] [blame] | 1011 | do { |
| 1012 | now = get_clock(); |
| 1013 | sequence = ACCESS_ONCE(idle->sequence); |
| 1014 | idle_time = ACCESS_ONCE(idle->idle_time); |
| 1015 | idle_enter = ACCESS_ONCE(idle->idle_enter); |
| 1016 | idle_exit = ACCESS_ONCE(idle->idle_exit); |
| 1017 | } while ((sequence & 1) || (idle->sequence != sequence)); |
| 1018 | idle_time += idle_enter ? ((idle_exit ? : now) - idle_enter) : 0; |
Martin Schwidefsky | 6f43092 | 2008-12-31 15:11:40 +0100 | [diff] [blame] | 1019 | return sprintf(buf, "%llu\n", idle_time >> 12); |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 1020 | } |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1021 | static DEVICE_ATTR(idle_time_us, 0444, show_idle_time, NULL); |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 1022 | |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1023 | static struct attribute *cpu_online_attrs[] = { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1024 | &dev_attr_capability.attr, |
| 1025 | &dev_attr_idle_count.attr, |
| 1026 | &dev_attr_idle_time_us.attr, |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 1027 | NULL, |
| 1028 | }; |
| 1029 | |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1030 | static struct attribute_group cpu_online_attr_group = { |
| 1031 | .attrs = cpu_online_attrs, |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 1032 | }; |
| 1033 | |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 1034 | static int __cpuinit smp_cpu_notify(struct notifier_block *self, |
| 1035 | unsigned long action, void *hcpu) |
| 1036 | { |
| 1037 | unsigned int cpu = (unsigned int)(long)hcpu; |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1038 | struct cpu *c = &pcpu_devices[cpu].cpu; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1039 | struct device *s = &c->dev; |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 1040 | struct s390_idle_data *idle; |
Akinobu Mita | d882ba6 | 2010-05-26 14:43:34 -0700 | [diff] [blame] | 1041 | int err = 0; |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 1042 | |
| 1043 | switch (action) { |
| 1044 | case CPU_ONLINE: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 1045 | case CPU_ONLINE_FROZEN: |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 1046 | idle = &per_cpu(s390_idle, cpu); |
Martin Schwidefsky | e98bbaa | 2009-06-22 12:08:20 +0200 | [diff] [blame] | 1047 | memset(idle, 0, sizeof(struct s390_idle_data)); |
Akinobu Mita | d882ba6 | 2010-05-26 14:43:34 -0700 | [diff] [blame] | 1048 | err = sysfs_create_group(&s->kobj, &cpu_online_attr_group); |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 1049 | break; |
| 1050 | case CPU_DEAD: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 1051 | case CPU_DEAD_FROZEN: |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1052 | sysfs_remove_group(&s->kobj, &cpu_online_attr_group); |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 1053 | break; |
| 1054 | } |
Akinobu Mita | d882ba6 | 2010-05-26 14:43:34 -0700 | [diff] [blame] | 1055 | return notifier_from_errno(err); |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | static struct notifier_block __cpuinitdata smp_cpu_nb = { |
Heiko Carstens | 39ce010 | 2007-04-27 16:02:00 +0200 | [diff] [blame] | 1059 | .notifier_call = smp_cpu_notify, |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 1060 | }; |
| 1061 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 1062 | static int __devinit smp_add_present_cpu(int cpu) |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1063 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1064 | struct cpu *c = &pcpu_devices[cpu].cpu; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1065 | struct device *s = &c->dev; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1066 | int rc; |
| 1067 | |
| 1068 | c->hotpluggable = 1; |
| 1069 | rc = register_cpu(c, cpu); |
| 1070 | if (rc) |
| 1071 | goto out; |
| 1072 | rc = sysfs_create_group(&s->kobj, &cpu_common_attr_group); |
| 1073 | if (rc) |
| 1074 | goto out_cpu; |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame] | 1075 | if (cpu_online(cpu)) { |
| 1076 | rc = sysfs_create_group(&s->kobj, &cpu_online_attr_group); |
| 1077 | if (rc) |
| 1078 | goto out_online; |
| 1079 | } |
| 1080 | rc = topology_cpu_init(c); |
| 1081 | if (rc) |
| 1082 | goto out_topology; |
| 1083 | return 0; |
| 1084 | |
| 1085 | out_topology: |
| 1086 | if (cpu_online(cpu)) |
| 1087 | sysfs_remove_group(&s->kobj, &cpu_online_attr_group); |
| 1088 | out_online: |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1089 | sysfs_remove_group(&s->kobj, &cpu_common_attr_group); |
| 1090 | out_cpu: |
| 1091 | #ifdef CONFIG_HOTPLUG_CPU |
| 1092 | unregister_cpu(c); |
| 1093 | #endif |
| 1094 | out: |
| 1095 | return rc; |
| 1096 | } |
| 1097 | |
| 1098 | #ifdef CONFIG_HOTPLUG_CPU |
Heiko Carstens | 1e48951 | 2008-04-30 13:38:37 +0200 | [diff] [blame] | 1099 | |
Heiko Carstens | 67060d9 | 2008-05-30 10:03:27 +0200 | [diff] [blame] | 1100 | int __ref smp_rescan_cpus(void) |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1101 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1102 | struct sclp_cpu_info *info; |
| 1103 | int nr; |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1104 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1105 | info = smp_get_cpu_info(); |
| 1106 | if (!info) |
| 1107 | return -ENOMEM; |
Martin Schwidefsky | 9d40d2e | 2008-01-26 14:11:31 +0100 | [diff] [blame] | 1108 | get_online_cpus(); |
Heiko Carstens | 0b18d31 | 2008-04-30 13:38:36 +0200 | [diff] [blame] | 1109 | mutex_lock(&smp_cpu_state_mutex); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1110 | nr = __smp_rescan_cpus(info, 1); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1111 | mutex_unlock(&smp_cpu_state_mutex); |
Heiko Carstens | 0b18d31 | 2008-04-30 13:38:36 +0200 | [diff] [blame] | 1112 | put_online_cpus(); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1113 | kfree(info); |
| 1114 | if (nr) |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 1115 | topology_schedule_update(); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1116 | return 0; |
Heiko Carstens | 1e48951 | 2008-04-30 13:38:37 +0200 | [diff] [blame] | 1117 | } |
| 1118 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1119 | static ssize_t __ref rescan_store(struct device *dev, |
| 1120 | struct device_attribute *attr, |
Andi Kleen | c9be0a3 | 2010-01-05 12:47:58 +0100 | [diff] [blame] | 1121 | const char *buf, |
Heiko Carstens | 1e48951 | 2008-04-30 13:38:37 +0200 | [diff] [blame] | 1122 | size_t count) |
| 1123 | { |
| 1124 | int rc; |
| 1125 | |
| 1126 | rc = smp_rescan_cpus(); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1127 | return rc ? rc : count; |
| 1128 | } |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1129 | static DEVICE_ATTR(rescan, 0200, NULL, rescan_store); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1130 | #endif /* CONFIG_HOTPLUG_CPU */ |
| 1131 | |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame] | 1132 | static int __init s390_smp_init(void) |
Heiko Carstens | c10fde0 | 2008-04-17 07:46:13 +0200 | [diff] [blame] | 1133 | { |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame] | 1134 | int cpu, rc; |
Heiko Carstens | 2fc2d1e | 2007-04-27 16:01:56 +0200 | [diff] [blame] | 1135 | |
| 1136 | register_cpu_notifier(&smp_cpu_nb); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1137 | #ifdef CONFIG_HOTPLUG_CPU |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1138 | rc = device_create_file(cpu_subsys.dev_root, &dev_attr_rescan); |
Heiko Carstens | 08d0796 | 2008-01-26 14:10:56 +0100 | [diff] [blame] | 1139 | if (rc) |
| 1140 | return rc; |
| 1141 | #endif |
| 1142 | for_each_present_cpu(cpu) { |
| 1143 | rc = smp_add_present_cpu(cpu); |
Heiko Carstens | fae8b22 | 2007-10-22 12:52:39 +0200 | [diff] [blame] | 1144 | if (rc) |
| 1145 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | } |
| 1147 | return 0; |
| 1148 | } |
Heiko Carstens | 83a24e3 | 2011-12-27 11:27:09 +0100 | [diff] [blame] | 1149 | subsys_initcall(s390_smp_init); |