blob: 512ce1cde2a4ca03c88350db6520581436968ba9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04002 * SMP related functions
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 1999, 2012
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04005 * Author(s): Denis Joseph Barrow,
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>,
7 * Heiko Carstens <heiko.carstens@de.ibm.com>,
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Heiko Carstens39ce0102007-04-27 16:02:00 +02009 * based on other smp stuff by
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * (c) 1995 Alan Cox, CymruNET Ltd <alan@cymru.net>
11 * (c) 1998 Ingo Molnar
12 *
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040013 * 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 Torvalds1da177e2005-04-16 15:20:36 -070016 */
17
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010018#define KMSG_COMPONENT "cpu"
19#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
20
Heiko Carstensf2308862011-01-05 12:48:08 +010021#include <linux/workqueue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
23#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/mm.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040025#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/spinlock.h>
27#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/interrupt.h>
Christian Borntraeger3324e602009-03-26 15:23:56 +010030#include <linux/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/cpu.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Michael Holzheu60a0c682011-10-30 15:16:40 +010033#include <linux/crash_dump.h>
Heiko Carstenscbb870c2010-02-26 22:37:43 +010034#include <asm/asm-offsets.h>
Heiko Carstens1e3cab22012-03-30 09:40:55 +020035#include <asm/switch_to.h>
36#include <asm/facility.h>
Michael Holzheu46b05d22007-02-21 10:55:21 +010037#include <asm/ipl.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010038#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/tlbflush.h>
Martin Schwidefsky27f6b412012-07-20 11:15:08 +020041#include <asm/vtimer.h>
Michael Holzheu411ed322007-04-27 16:01:49 +020042#include <asm/lowcore.h>
Heiko Carstens08d07962008-01-26 14:10:56 +010043#include <asm/sclp.h>
Martin Schwidefskyc742b312008-12-31 15:11:42 +010044#include <asm/vdso.h>
Michael Holzheu3ab121a2012-03-11 11:59:32 -040045#include <asm/debug.h>
Michael Holzheu4857d4b2012-03-11 11:59:34 -040046#include <asm/os_info.h>
Heiko Carstensa9ae32c2012-06-04 12:55:15 +020047#include <asm/sigp.h>
Heiko Carstensa8061702008-04-17 07:46:26 +020048#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040050enum {
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040051 ec_schedule = 0,
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040052 ec_call_function_single,
53 ec_stop_cpu,
54};
Heiko Carstens08d07962008-01-26 14:10:56 +010055
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040056enum {
Heiko Carstens08d07962008-01-26 14:10:56 +010057 CPU_STATE_STANDBY,
58 CPU_STATE_CONFIGURED,
59};
60
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040061struct pcpu {
Heiko Carstens96619fc2013-12-05 12:42:09 +010062 struct cpu *cpu;
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040063 struct _lowcore *lowcore; /* lowcore page(s) for the cpu */
64 unsigned long async_stack; /* async stack for the cpu */
65 unsigned long panic_stack; /* panic stack for the cpu */
66 unsigned long ec_mask; /* bit mask for ec_xxx functions */
67 int state; /* physical cpu state */
Heiko Carstens50ab9a92012-09-04 17:36:16 +020068 int polarization; /* physical polarization */
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040069 u16 address; /* physical cpu address */
70};
71
72static u8 boot_cpu_type;
73static u16 boot_cpu_address;
74static struct pcpu pcpu_devices[NR_CPUS];
75
Heiko Carstens50ab9a92012-09-04 17:36:16 +020076/*
77 * The smp_cpu_state_mutex must be held when changing the state or polarization
78 * member of a pcpu data structure within the pcpu_devices arreay.
79 */
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020080DEFINE_MUTEX(smp_cpu_state_mutex);
Heiko Carstens08d07962008-01-26 14:10:56 +010081
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040082/*
83 * Signal processor helper functions.
84 */
85static inline int __pcpu_sigp(u16 addr, u8 order, u32 parm, u32 *status)
Heiko Carstens5c0b9122009-09-11 10:29:05 +020086{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040087 register unsigned int reg1 asm ("1") = parm;
88 int cc;
Heiko Carstens5c0b9122009-09-11 10:29:05 +020089
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -040090 asm volatile(
91 " sigp %1,%2,0(%3)\n"
92 " ipm %0\n"
93 " srl %0,28\n"
94 : "=d" (cc), "+d" (reg1) : "d" (addr), "a" (order) : "cc");
95 if (status && cc == 1)
96 *status = reg1;
97 return cc;
Heiko Carstens5c0b9122009-09-11 10:29:05 +020098}
99
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400100static inline int __pcpu_sigp_relax(u16 addr, u8 order, u32 parm, u32 *status)
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100101{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400102 int cc;
103
104 while (1) {
Heiko Carstensc5e3acd2012-08-30 14:24:42 +0200105 cc = __pcpu_sigp(addr, order, parm, NULL);
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200106 if (cc != SIGP_CC_BUSY)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400107 return cc;
108 cpu_relax();
109 }
110}
111
112static int pcpu_sigp_retry(struct pcpu *pcpu, u8 order, u32 parm)
113{
114 int cc, retry;
115
116 for (retry = 0; ; retry++) {
Heiko Carstensc5e3acd2012-08-30 14:24:42 +0200117 cc = __pcpu_sigp(pcpu->address, order, parm, NULL);
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200118 if (cc != SIGP_CC_BUSY)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400119 break;
120 if (retry >= 3)
121 udelay(10);
122 }
123 return cc;
124}
125
126static inline int pcpu_stopped(struct pcpu *pcpu)
127{
Heiko Carstens41459d32012-09-14 11:09:52 +0200128 u32 uninitialized_var(status);
Heiko Carstensc5e3acd2012-08-30 14:24:42 +0200129
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200130 if (__pcpu_sigp(pcpu->address, SIGP_SENSE,
Heiko Carstensc5e3acd2012-08-30 14:24:42 +0200131 0, &status) != SIGP_CC_STATUS_STORED)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400132 return 0;
Heiko Carstensc5e3acd2012-08-30 14:24:42 +0200133 return !!(status & (SIGP_STATUS_CHECK_STOP|SIGP_STATUS_STOPPED));
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400134}
135
136static inline int pcpu_running(struct pcpu *pcpu)
137{
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200138 if (__pcpu_sigp(pcpu->address, SIGP_SENSE_RUNNING,
Heiko Carstensc5e3acd2012-08-30 14:24:42 +0200139 0, NULL) != SIGP_CC_STATUS_STORED)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400140 return 1;
Heiko Carstens524b24a2012-06-04 12:11:41 +0200141 /* Status stored condition code is equivalent to cpu not running. */
142 return 0;
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100143}
144
Michael Holzheu1943f532011-10-30 15:16:38 +0100145/*
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400146 * Find struct pcpu by cpu address.
Michael Holzheu1943f532011-10-30 15:16:38 +0100147 */
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400148static struct pcpu *pcpu_find_address(const struct cpumask *mask, int address)
Michael Holzheu1943f532011-10-30 15:16:38 +0100149{
150 int cpu;
151
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400152 for_each_cpu(cpu, mask)
153 if (pcpu_devices[cpu].address == address)
154 return pcpu_devices + cpu;
155 return NULL;
156}
157
158static void pcpu_ec_call(struct pcpu *pcpu, int ec_bit)
159{
160 int order;
161
Heiko Carstensdea24192013-12-03 10:06:29 +0100162 if (test_and_set_bit(ec_bit, &pcpu->ec_mask))
163 return;
164 order = pcpu_running(pcpu) ? SIGP_EXTERNAL_CALL : SIGP_EMERGENCY_SIGNAL;
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400165 pcpu_sigp_retry(pcpu, order, 0);
166}
167
Paul Gortmakere2741f12013-06-18 17:04:52 -0400168static int pcpu_alloc_lowcore(struct pcpu *pcpu, int cpu)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400169{
170 struct _lowcore *lc;
171
172 if (pcpu != &pcpu_devices[0]) {
173 pcpu->lowcore = (struct _lowcore *)
174 __get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER);
175 pcpu->async_stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
176 pcpu->panic_stack = __get_free_page(GFP_KERNEL);
177 if (!pcpu->lowcore || !pcpu->panic_stack || !pcpu->async_stack)
178 goto out;
Michael Holzheu1943f532011-10-30 15:16:38 +0100179 }
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400180 lc = pcpu->lowcore;
181 memcpy(lc, &S390_lowcore, 512);
182 memset((char *) lc + 512, 0, sizeof(*lc) - 512);
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200183 lc->async_stack = pcpu->async_stack + ASYNC_SIZE
184 - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
185 lc->panic_stack = pcpu->panic_stack + PAGE_SIZE
186 - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400187 lc->cpu_nr = cpu;
188#ifndef CONFIG_64BIT
189 if (MACHINE_HAS_IEEE) {
190 lc->extended_save_area_addr = get_zeroed_page(GFP_KERNEL);
191 if (!lc->extended_save_area_addr)
192 goto out;
193 }
194#else
195 if (vdso_alloc_per_cpu(lc))
196 goto out;
197#endif
198 lowcore_ptr[cpu] = lc;
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200199 pcpu_sigp_retry(pcpu, SIGP_SET_PREFIX, (u32)(unsigned long) lc);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400200 return 0;
201out:
202 if (pcpu != &pcpu_devices[0]) {
203 free_page(pcpu->panic_stack);
204 free_pages(pcpu->async_stack, ASYNC_ORDER);
205 free_pages((unsigned long) pcpu->lowcore, LC_ORDER);
206 }
207 return -ENOMEM;
Michael Holzheu1943f532011-10-30 15:16:38 +0100208}
209
Heiko Carstens9d0f46a2012-05-09 16:27:35 +0200210#ifdef CONFIG_HOTPLUG_CPU
211
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400212static void pcpu_free_lowcore(struct pcpu *pcpu)
Heiko Carstens2c2df112010-02-26 22:37:34 +0100213{
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200214 pcpu_sigp_retry(pcpu, SIGP_SET_PREFIX, 0);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400215 lowcore_ptr[pcpu - pcpu_devices] = NULL;
216#ifndef CONFIG_64BIT
217 if (MACHINE_HAS_IEEE) {
218 struct _lowcore *lc = pcpu->lowcore;
Heiko Carstens2c2df112010-02-26 22:37:34 +0100219
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400220 free_page((unsigned long) lc->extended_save_area_addr);
221 lc->extended_save_area_addr = 0;
222 }
223#else
224 vdso_free_per_cpu(pcpu->lowcore);
225#endif
226 if (pcpu != &pcpu_devices[0]) {
227 free_page(pcpu->panic_stack);
228 free_pages(pcpu->async_stack, ASYNC_ORDER);
229 free_pages((unsigned long) pcpu->lowcore, LC_ORDER);
230 }
Heiko Carstens2c2df112010-02-26 22:37:34 +0100231}
232
Heiko Carstens9d0f46a2012-05-09 16:27:35 +0200233#endif /* CONFIG_HOTPLUG_CPU */
234
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400235static void pcpu_prepare_secondary(struct pcpu *pcpu, int cpu)
Martin Schwidefsky85ac7ca2011-12-27 11:27:22 +0100236{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400237 struct _lowcore *lc = pcpu->lowcore;
238
Martin Schwidefsky1b948d62014-04-03 13:55:01 +0200239 if (MACHINE_HAS_TLB_LC)
240 cpumask_set_cpu(cpu, &init_mm.context.cpu_attach_mask);
241 cpumask_set_cpu(cpu, mm_cpumask(&init_mm));
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400242 atomic_inc(&init_mm.context.attach_count);
243 lc->cpu_nr = cpu;
244 lc->percpu_offset = __per_cpu_offset[cpu];
245 lc->kernel_asce = S390_lowcore.kernel_asce;
246 lc->machine_flags = S390_lowcore.machine_flags;
247 lc->ftrace_func = S390_lowcore.ftrace_func;
248 lc->user_timer = lc->system_timer = lc->steal_timer = 0;
249 __ctl_store(lc->cregs_save_area, 0, 15);
250 save_access_regs((unsigned int *) lc->access_regs_save_area);
251 memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
252 MAX_FACILITY_BIT/8);
Martin Schwidefsky85ac7ca2011-12-27 11:27:22 +0100253}
254
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400255static void pcpu_attach_task(struct pcpu *pcpu, struct task_struct *tsk)
256{
257 struct _lowcore *lc = pcpu->lowcore;
258 struct thread_info *ti = task_thread_info(tsk);
259
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200260 lc->kernel_stack = (unsigned long) task_stack_page(tsk)
261 + THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400262 lc->thread_info = (unsigned long) task_thread_info(tsk);
263 lc->current_task = (unsigned long) tsk;
264 lc->user_timer = ti->user_timer;
265 lc->system_timer = ti->system_timer;
266 lc->steal_timer = 0;
267}
268
269static void pcpu_start_fn(struct pcpu *pcpu, void (*func)(void *), void *data)
270{
271 struct _lowcore *lc = pcpu->lowcore;
272
273 lc->restart_stack = lc->kernel_stack;
274 lc->restart_fn = (unsigned long) func;
275 lc->restart_data = (unsigned long) data;
276 lc->restart_source = -1UL;
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200277 pcpu_sigp_retry(pcpu, SIGP_RESTART, 0);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400278}
279
280/*
281 * Call function via PSW restart on pcpu and stop the current cpu.
282 */
283static void pcpu_delegate(struct pcpu *pcpu, void (*func)(void *),
284 void *data, unsigned long stack)
285{
Michael Holzheu061da3d2012-05-24 14:38:26 +0200286 struct _lowcore *lc = lowcore_ptr[pcpu - pcpu_devices];
Heiko Carstensfbe76562012-06-05 09:59:52 +0200287 unsigned long source_cpu = stap();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400288
Martin Schwidefskye258d712013-09-24 09:14:56 +0200289 __load_psw_mask(PSW_KERNEL_BITS);
Heiko Carstensfbe76562012-06-05 09:59:52 +0200290 if (pcpu->address == source_cpu)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400291 func(data); /* should not return */
292 /* Stop target cpu (if func returns this stops the current cpu). */
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200293 pcpu_sigp_retry(pcpu, SIGP_STOP, 0);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400294 /* Restart func on the target cpu and stop the current cpu. */
Heiko Carstensfbe76562012-06-05 09:59:52 +0200295 mem_assign_absolute(lc->restart_stack, stack);
296 mem_assign_absolute(lc->restart_fn, (unsigned long) func);
297 mem_assign_absolute(lc->restart_data, (unsigned long) data);
298 mem_assign_absolute(lc->restart_source, source_cpu);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400299 asm volatile(
Heiko Carstenseb546192012-06-04 15:05:43 +0200300 "0: sigp 0,%0,%2 # sigp restart to target cpu\n"
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400301 " brc 2,0b # busy, try again\n"
Heiko Carstenseb546192012-06-04 15:05:43 +0200302 "1: sigp 0,%1,%3 # sigp stop to current cpu\n"
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400303 " brc 2,1b # busy, try again\n"
Heiko Carstensfbe76562012-06-05 09:59:52 +0200304 : : "d" (pcpu->address), "d" (source_cpu),
Heiko Carstenseb546192012-06-04 15:05:43 +0200305 "K" (SIGP_RESTART), "K" (SIGP_STOP)
306 : "0", "1", "cc");
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400307 for (;;) ;
308}
309
310/*
311 * Call function on an online CPU.
312 */
313void smp_call_online_cpu(void (*func)(void *), void *data)
314{
315 struct pcpu *pcpu;
316
317 /* Use the current cpu if it is online. */
318 pcpu = pcpu_find_address(cpu_online_mask, stap());
319 if (!pcpu)
320 /* Use the first online cpu. */
321 pcpu = pcpu_devices + cpumask_first(cpu_online_mask);
322 pcpu_delegate(pcpu, func, data, (unsigned long) restart_stack);
323}
324
325/*
326 * Call function on the ipl CPU.
327 */
328void smp_call_ipl_cpu(void (*func)(void *), void *data)
329{
Michael Holzheuc6da39f2012-03-13 11:25:08 -0400330 pcpu_delegate(&pcpu_devices[0], func, data,
331 pcpu_devices->panic_stack + PAGE_SIZE);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400332}
333
334int smp_find_processor_id(u16 address)
335{
336 int cpu;
337
338 for_each_present_cpu(cpu)
339 if (pcpu_devices[cpu].address == address)
340 return cpu;
341 return -1;
342}
343
344int smp_vcpu_scheduled(int cpu)
345{
346 return pcpu_running(pcpu_devices + cpu);
347}
348
349void smp_yield(void)
350{
351 if (MACHINE_HAS_DIAG44)
352 asm volatile("diag 0,0,0x44");
353}
354
355void smp_yield_cpu(int cpu)
356{
357 if (MACHINE_HAS_DIAG9C)
358 asm volatile("diag %0,0,0x9c"
359 : : "d" (pcpu_devices[cpu].address));
360 else if (MACHINE_HAS_DIAG44)
361 asm volatile("diag 0,0,0x44");
362}
363
364/*
365 * Send cpus emergency shutdown signal. This gives the cpus the
366 * opportunity to complete outstanding interrupts.
367 */
Heiko Carstens63df41d62013-09-06 19:10:48 +0200368static void smp_emergency_stop(cpumask_t *cpumask)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400369{
370 u64 end;
371 int cpu;
372
Heiko Carstens1aae0562013-01-30 09:49:40 +0100373 end = get_tod_clock() + (1000000UL << 12);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400374 for_each_cpu(cpu, cpumask) {
375 struct pcpu *pcpu = pcpu_devices + cpu;
376 set_bit(ec_stop_cpu, &pcpu->ec_mask);
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200377 while (__pcpu_sigp(pcpu->address, SIGP_EMERGENCY_SIGNAL,
378 0, NULL) == SIGP_CC_BUSY &&
Heiko Carstens1aae0562013-01-30 09:49:40 +0100379 get_tod_clock() < end)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400380 cpu_relax();
381 }
Heiko Carstens1aae0562013-01-30 09:49:40 +0100382 while (get_tod_clock() < end) {
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400383 for_each_cpu(cpu, cpumask)
384 if (pcpu_stopped(pcpu_devices + cpu))
385 cpumask_clear_cpu(cpu, cpumask);
386 if (cpumask_empty(cpumask))
387 break;
388 cpu_relax();
389 }
390}
391
392/*
393 * Stop all cpus but the current one.
394 */
Heiko Carstens677d7622007-11-20 11:13:37 +0100395void smp_send_stop(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Martin Schwidefsky85ac7ca2011-12-27 11:27:22 +0100397 cpumask_t cpumask;
398 int cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Heiko Carstens677d7622007-11-20 11:13:37 +0100400 /* Disable all interrupts/machine checks */
Martin Schwidefskye258d712013-09-24 09:14:56 +0200401 __load_psw_mask(PSW_KERNEL_BITS | PSW_MASK_DAT);
Christian Borntraeger3324e602009-03-26 15:23:56 +0100402 trace_hardirqs_off();
Heiko Carstens677d7622007-11-20 11:13:37 +0100403
Michael Holzheu3ab121a2012-03-11 11:59:32 -0400404 debug_set_critical();
Martin Schwidefsky85ac7ca2011-12-27 11:27:22 +0100405 cpumask_copy(&cpumask, cpu_online_mask);
406 cpumask_clear_cpu(smp_processor_id(), &cpumask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400408 if (oops_in_progress)
409 smp_emergency_stop(&cpumask);
Martin Schwidefsky85ac7ca2011-12-27 11:27:22 +0100410
411 /* stop all processors */
412 for_each_cpu(cpu, &cpumask) {
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400413 struct pcpu *pcpu = pcpu_devices + cpu;
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200414 pcpu_sigp_retry(pcpu, SIGP_STOP, 0);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400415 while (!pcpu_stopped(pcpu))
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100416 cpu_relax();
417 }
418}
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420/*
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400421 * Stop the current cpu.
422 */
423void smp_stop_cpu(void)
424{
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200425 pcpu_sigp_retry(pcpu_devices + smp_processor_id(), SIGP_STOP, 0);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400426 for (;;) ;
427}
428
429/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 * This is the main routine where commands issued by other
431 * cpus are handled.
432 */
Heiko Carstens9acf73b2013-05-22 10:24:37 +0200433static void smp_handle_ext_call(void)
434{
435 unsigned long bits;
436
437 /* handle bit signal external calls */
438 bits = xchg(&pcpu_devices[smp_processor_id()].ec_mask, 0);
439 if (test_bit(ec_stop_cpu, &bits))
440 smp_stop_cpu();
441 if (test_bit(ec_schedule, &bits))
442 scheduler_ipi();
Heiko Carstens9acf73b2013-05-22 10:24:37 +0200443 if (test_bit(ec_call_function_single, &bits))
444 generic_smp_call_function_single_interrupt();
445}
446
Heiko Carstensfde15c32012-03-11 11:59:31 -0400447static void do_ext_call_interrupt(struct ext_code ext_code,
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200448 unsigned int param32, unsigned long param64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449{
Heiko Carstens9acf73b2013-05-22 10:24:37 +0200450 inc_irq_stat(ext_code.code == 0x1202 ? IRQEXT_EXC : IRQEXT_EMS);
451 smp_handle_ext_call();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
Rusty Russell630cd042009-09-24 09:34:45 -0600454void arch_send_call_function_ipi_mask(const struct cpumask *mask)
Heiko Carstensca9fc752008-12-25 13:38:39 +0100455{
456 int cpu;
457
Rusty Russell630cd042009-09-24 09:34:45 -0600458 for_each_cpu(cpu, mask)
Heiko Carstensb6ed49e2013-05-21 15:34:56 +0200459 pcpu_ec_call(pcpu_devices + cpu, ec_call_function_single);
Heiko Carstensca9fc752008-12-25 13:38:39 +0100460}
461
462void arch_send_call_function_single_ipi(int cpu)
463{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400464 pcpu_ec_call(pcpu_devices + cpu, ec_call_function_single);
Heiko Carstensca9fc752008-12-25 13:38:39 +0100465}
466
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800467#ifndef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468/*
469 * this function sends a 'purge tlb' signal to another CPU.
470 */
Heiko Carstensa8061702008-04-17 07:46:26 +0200471static void smp_ptlb_callback(void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200473 __tlb_flush_local();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
475
476void smp_ptlb_all(void)
477{
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200478 on_each_cpu(smp_ptlb_callback, NULL, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480EXPORT_SYMBOL(smp_ptlb_all);
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800481#endif /* ! CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483/*
484 * this function sends a 'reschedule' IPI to another CPU.
485 * it goes straight through and wastes no time serializing
486 * anything. Worst case is that we lose a reschedule ...
487 */
488void smp_send_reschedule(int cpu)
489{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400490 pcpu_ec_call(pcpu_devices + cpu, ec_schedule);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491}
492
493/*
494 * parameter area for the set/clear control bit callbacks
495 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200496struct ec_creg_mask_parms {
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400497 unsigned long orval;
498 unsigned long andval;
499 int cr;
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200500};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502/*
503 * callback for setting/clearing control bits
504 */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200505static void smp_ctl_bit_callback(void *info)
506{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200507 struct ec_creg_mask_parms *pp = info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 unsigned long cregs[16];
Heiko Carstens39ce0102007-04-27 16:02:00 +0200509
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200510 __ctl_store(cregs, 0, 15);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400511 cregs[pp->cr] = (cregs[pp->cr] & pp->andval) | pp->orval;
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200512 __ctl_load(cregs, 0, 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
515/*
516 * Set a bit in a control register of all cpus
517 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200518void smp_ctl_set_bit(int cr, int bit)
519{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400520 struct ec_creg_mask_parms parms = { 1UL << bit, -1UL, cr };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200522 on_each_cpu(smp_ctl_bit_callback, &parms, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523}
Heiko Carstens39ce0102007-04-27 16:02:00 +0200524EXPORT_SYMBOL(smp_ctl_set_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526/*
527 * Clear a bit in a control register of all cpus
528 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200529void smp_ctl_clear_bit(int cr, int bit)
530{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400531 struct ec_creg_mask_parms parms = { 0, ~(1UL << bit), cr };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200533 on_each_cpu(smp_ctl_bit_callback, &parms, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534}
Heiko Carstens39ce0102007-04-27 16:02:00 +0200535EXPORT_SYMBOL(smp_ctl_clear_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Michael Holzheu60a0c682011-10-30 15:16:40 +0100537#if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_CRASH_DUMP)
Michael Holzheu411ed322007-04-27 16:01:49 +0200538
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400539static void __init smp_get_save_area(int cpu, u16 address)
Heiko Carstens08d07962008-01-26 14:10:56 +0100540{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400541 void *lc = pcpu_devices[0].lowcore;
542 struct save_area *save_area;
Heiko Carstens08d07962008-01-26 14:10:56 +0100543
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400544 if (is_kdump_kernel())
545 return;
546 if (!OLDMEM_BASE && (address == boot_cpu_address ||
547 ipl_info.type != IPL_TYPE_FCP_DUMP))
548 return;
Michael Holzheu58952942013-10-11 10:29:23 +0200549 save_area = dump_save_area_create(cpu);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400550 if (!save_area)
551 panic("could not allocate memory for save area\n");
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400552#ifdef CONFIG_CRASH_DUMP
553 if (address == boot_cpu_address) {
554 /* Copy the registers of the boot cpu. */
555 copy_oldmem_page(1, (void *) save_area, sizeof(*save_area),
556 SAVE_AREA_BASE - PAGE_SIZE, 0);
557 return;
558 }
559#endif
560 /* Get the registers of a non-boot cpu. */
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200561 __pcpu_sigp_relax(address, SIGP_STOP_AND_STORE_STATUS, 0, NULL);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400562 memcpy_real(save_area, lc + SAVE_AREA_BASE, sizeof(*save_area));
563}
564
565int smp_store_status(int cpu)
566{
567 struct pcpu *pcpu;
568
569 pcpu = pcpu_devices + cpu;
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200570 if (__pcpu_sigp_relax(pcpu->address, SIGP_STOP_AND_STORE_STATUS,
571 0, NULL) != SIGP_CC_ORDER_CODE_ACCEPTED)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400572 return -EIO;
Heiko Carstens08d07962008-01-26 14:10:56 +0100573 return 0;
574}
575
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400576#else /* CONFIG_ZFCPDUMP || CONFIG_CRASH_DUMP */
Heiko Carstens08d07962008-01-26 14:10:56 +0100577
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400578static inline void smp_get_save_area(int cpu, u16 address) { }
Heiko Carstens08d07962008-01-26 14:10:56 +0100579
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400580#endif /* CONFIG_ZFCPDUMP || CONFIG_CRASH_DUMP */
581
Heiko Carstens50ab9a92012-09-04 17:36:16 +0200582void smp_cpu_set_polarization(int cpu, int val)
583{
584 pcpu_devices[cpu].polarization = val;
585}
586
587int smp_cpu_get_polarization(int cpu)
588{
589 return pcpu_devices[cpu].polarization;
590}
591
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400592static struct sclp_cpu_info *smp_get_cpu_info(void)
Heiko Carstens08d07962008-01-26 14:10:56 +0100593{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400594 static int use_sigp_detection;
Heiko Carstens08d07962008-01-26 14:10:56 +0100595 struct sclp_cpu_info *info;
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400596 int address;
Heiko Carstens08d07962008-01-26 14:10:56 +0100597
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400598 info = kzalloc(sizeof(*info), GFP_KERNEL);
599 if (info && (use_sigp_detection || sclp_get_cpu_info(info))) {
600 use_sigp_detection = 1;
601 for (address = 0; address <= MAX_CPU_ADDRESS; address++) {
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200602 if (__pcpu_sigp_relax(address, SIGP_SENSE, 0, NULL) ==
603 SIGP_CC_NOT_OPERATIONAL)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400604 continue;
605 info->cpu[info->configured].address = address;
606 info->configured++;
607 }
608 info->combined = info->configured;
Heiko Carstens08d07962008-01-26 14:10:56 +0100609 }
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400610 return info;
Heiko Carstens08d07962008-01-26 14:10:56 +0100611}
612
Paul Gortmakere2741f12013-06-18 17:04:52 -0400613static int smp_add_present_cpu(int cpu);
Heiko Carstens08d07962008-01-26 14:10:56 +0100614
Paul Gortmakere2741f12013-06-18 17:04:52 -0400615static int __smp_rescan_cpus(struct sclp_cpu_info *info, int sysfs_add)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400616{
617 struct pcpu *pcpu;
618 cpumask_t avail;
619 int cpu, nr, i;
620
621 nr = 0;
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +0200622 cpumask_xor(&avail, cpu_possible_mask, cpu_present_mask);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400623 cpu = cpumask_first(&avail);
624 for (i = 0; (i < info->combined) && (cpu < nr_cpu_ids); i++) {
625 if (info->has_cpu_type && info->cpu[i].type != boot_cpu_type)
626 continue;
627 if (pcpu_find_address(cpu_present_mask, info->cpu[i].address))
628 continue;
629 pcpu = pcpu_devices + cpu;
630 pcpu->address = info->cpu[i].address;
Martin Schwidefskya4eeea42013-05-15 16:53:07 +0200631 pcpu->state = (i >= info->configured) ?
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400632 CPU_STATE_STANDBY : CPU_STATE_CONFIGURED;
Heiko Carstens50ab9a92012-09-04 17:36:16 +0200633 smp_cpu_set_polarization(cpu, POLARIZATION_UNKNOWN);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400634 set_cpu_present(cpu, true);
635 if (sysfs_add && smp_add_present_cpu(cpu) != 0)
636 set_cpu_present(cpu, false);
637 else
638 nr++;
639 cpu = cpumask_next(cpu, &avail);
640 }
641 return nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642}
643
Heiko Carstens48483b32008-01-26 14:11:05 +0100644static void __init smp_detect_cpus(void)
645{
646 unsigned int cpu, c_cpus, s_cpus;
647 struct sclp_cpu_info *info;
Heiko Carstens48483b32008-01-26 14:11:05 +0100648
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400649 info = smp_get_cpu_info();
Heiko Carstens48483b32008-01-26 14:11:05 +0100650 if (!info)
651 panic("smp_detect_cpus failed to allocate memory\n");
Heiko Carstens48483b32008-01-26 14:11:05 +0100652 if (info->has_cpu_type) {
653 for (cpu = 0; cpu < info->combined; cpu++) {
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400654 if (info->cpu[cpu].address != boot_cpu_address)
655 continue;
656 /* The boot cpu dictates the cpu type. */
657 boot_cpu_type = info->cpu[cpu].type;
658 break;
Heiko Carstens48483b32008-01-26 14:11:05 +0100659 }
660 }
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400661 c_cpus = s_cpus = 0;
Heiko Carstens48483b32008-01-26 14:11:05 +0100662 for (cpu = 0; cpu < info->combined; cpu++) {
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400663 if (info->has_cpu_type && info->cpu[cpu].type != boot_cpu_type)
Heiko Carstens48483b32008-01-26 14:11:05 +0100664 continue;
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400665 if (cpu < info->configured) {
666 smp_get_save_area(c_cpus, info->cpu[cpu].address);
667 c_cpus++;
668 } else
Heiko Carstens48483b32008-01-26 14:11:05 +0100669 s_cpus++;
Heiko Carstens48483b32008-01-26 14:11:05 +0100670 }
Martin Schwidefsky395d31d2008-12-25 13:39:50 +0100671 pr_info("%d configured CPUs, %d standby CPUs\n", c_cpus, s_cpus);
Martin Schwidefsky9d40d2e2008-01-26 14:11:31 +0100672 get_online_cpus();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400673 __smp_rescan_cpus(info, 0);
Martin Schwidefsky9d40d2e2008-01-26 14:11:31 +0100674 put_online_cpus();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400675 kfree(info);
Heiko Carstens48483b32008-01-26 14:11:05 +0100676}
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678/*
Heiko Carstens39ce0102007-04-27 16:02:00 +0200679 * Activate a secondary processor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 */
Paul Gortmakere2741f12013-06-18 17:04:52 -0400681static void smp_start_secondary(void *cpuvoid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
Heiko Carstens1aae0562013-01-30 09:49:40 +0100683 S390_lowcore.last_update_clock = get_tod_clock();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400684 S390_lowcore.restart_stack = (unsigned long) restart_stack;
685 S390_lowcore.restart_fn = (unsigned long) do_restart;
686 S390_lowcore.restart_data = 0;
687 S390_lowcore.restart_source = -1UL;
688 restore_access_regs(S390_lowcore.access_regs_save_area);
689 __ctl_load(S390_lowcore.cregs_save_area, 0, 15);
Martin Schwidefskye258d712013-09-24 09:14:56 +0200690 __load_psw_mask(PSW_KERNEL_BITS | PSW_MASK_DAT);
Heiko Carstens39ce0102007-04-27 16:02:00 +0200691 cpu_init();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800692 preempt_disable();
Heiko Carstens39ce0102007-04-27 16:02:00 +0200693 init_cpu_timer();
Heiko Carstens39ce0102007-04-27 16:02:00 +0200694 init_cpu_vtimer();
Heiko Carstens29b08d22006-12-04 15:40:40 +0100695 pfault_init();
Manfred Spraule545a612008-09-07 16:57:22 +0200696 notify_cpu_starting(smp_processor_id());
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +0200697 set_cpu_online(smp_processor_id(), true);
Heiko Carstens93f3b2e2013-01-02 16:54:12 +0100698 inc_irq_stat(CPU_RST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 local_irq_enable();
Thomas Gleixner52c00652013-03-21 22:49:57 +0100700 cpu_startup_entry(CPUHP_ONLINE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701}
702
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703/* Upping and downing of CPUs */
Paul Gortmakere2741f12013-06-18 17:04:52 -0400704int __cpu_up(unsigned int cpu, struct task_struct *tidle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400706 struct pcpu *pcpu;
707 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400709 pcpu = pcpu_devices + cpu;
710 if (pcpu->state != CPU_STATE_CONFIGURED)
Heiko Carstens08d07962008-01-26 14:10:56 +0100711 return -EIO;
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200712 if (pcpu_sigp_retry(pcpu, SIGP_INITIAL_CPU_RESET, 0) !=
713 SIGP_CC_ORDER_CODE_ACCEPTED)
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400714 return -EIO;
Thomas Gleixnere80e7812012-04-20 13:05:52 +0000715
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400716 rc = pcpu_alloc_lowcore(pcpu, cpu);
717 if (rc)
718 return rc;
719 pcpu_prepare_secondary(pcpu, cpu);
Thomas Gleixnere80e7812012-04-20 13:05:52 +0000720 pcpu_attach_task(pcpu, tidle);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400721 pcpu_start_fn(pcpu, smp_start_secondary, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 while (!cpu_online(cpu))
723 cpu_relax();
724 return 0;
725}
726
Heiko Carstensd80512f2013-12-16 14:31:26 +0100727static unsigned int setup_possible_cpus __initdata;
Heiko Carstens48483b32008-01-26 14:11:05 +0100728
Heiko Carstensd80512f2013-12-16 14:31:26 +0100729static int __init _setup_possible_cpus(char *s)
730{
731 get_option(&s, &setup_possible_cpus);
Heiko Carstens37a33022006-02-17 13:52:47 -0800732 return 0;
733}
Heiko Carstensd80512f2013-12-16 14:31:26 +0100734early_param("possible_cpus", _setup_possible_cpus);
Heiko Carstens37a33022006-02-17 13:52:47 -0800735
Heiko Carstens48483b32008-01-26 14:11:05 +0100736#ifdef CONFIG_HOTPLUG_CPU
737
Heiko Carstens39ce0102007-04-27 16:02:00 +0200738int __cpu_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400740 unsigned long cregs[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Heiko Carstens9acf73b2013-05-22 10:24:37 +0200742 /* Handle possible pending IPIs */
743 smp_handle_ext_call();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400744 set_cpu_online(smp_processor_id(), false);
745 /* Disable pseudo page faults on this cpu. */
Heiko Carstens29b08d22006-12-04 15:40:40 +0100746 pfault_fini();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400747 /* Disable interrupt sources via control register. */
748 __ctl_store(cregs, 0, 15);
749 cregs[0] &= ~0x0000ee70UL; /* disable all external interrupts */
750 cregs[6] &= ~0xff000000UL; /* disable all I/O interrupts */
751 cregs[14] &= ~0x1f000000UL; /* disable most machine checks */
752 __ctl_load(cregs, 0, 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 return 0;
754}
755
Heiko Carstens39ce0102007-04-27 16:02:00 +0200756void __cpu_die(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400758 struct pcpu *pcpu;
759
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 /* Wait until target cpu is down */
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400761 pcpu = pcpu_devices + cpu;
762 while (!pcpu_stopped(pcpu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 cpu_relax();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400764 pcpu_free_lowcore(pcpu);
Martin Schwidefsky050eef32010-08-24 09:26:21 +0200765 atomic_dec(&init_mm.context.attach_count);
Martin Schwidefsky1b948d62014-04-03 13:55:01 +0200766 cpumask_clear_cpu(cpu, mm_cpumask(&init_mm));
767 if (MACHINE_HAS_TLB_LC)
768 cpumask_clear_cpu(cpu, &init_mm.context.cpu_attach_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769}
770
Heiko Carstensb456d942011-05-23 10:24:33 +0200771void __noreturn cpu_die(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
773 idle_task_exit();
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200774 pcpu_sigp_retry(pcpu_devices + smp_processor_id(), SIGP_STOP, 0);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400775 for (;;) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776}
777
Heiko Carstens255acee2006-02-17 13:52:46 -0800778#endif /* CONFIG_HOTPLUG_CPU */
779
Heiko Carstensd80512f2013-12-16 14:31:26 +0100780void __init smp_fill_possible_mask(void)
781{
Heiko Carstenscf813db2014-03-10 14:50:16 +0100782 unsigned int possible, sclp, cpu;
Heiko Carstensd80512f2013-12-16 14:31:26 +0100783
Heiko Carstenscf813db2014-03-10 14:50:16 +0100784 sclp = sclp_get_max_cpu() ?: nr_cpu_ids;
785 possible = setup_possible_cpus ?: nr_cpu_ids;
786 possible = min(possible, sclp);
Heiko Carstensd80512f2013-12-16 14:31:26 +0100787 for (cpu = 0; cpu < possible && cpu < nr_cpu_ids; cpu++)
788 set_cpu_possible(cpu, true);
789}
790
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791void __init smp_prepare_cpus(unsigned int max_cpus)
792{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200793 /* request the 0x1201 emergency signal external interrupt */
Thomas Huth1dad0932014-03-31 15:24:08 +0200794 if (register_external_irq(EXT_IRQ_EMERGENCY_SIG, do_ext_call_interrupt))
Heiko Carstens39ce0102007-04-27 16:02:00 +0200795 panic("Couldn't request external interrupt 0x1201");
Martin Schwidefskyd98e19c2011-10-30 15:16:58 +0100796 /* request the 0x1202 external call external interrupt */
Thomas Huth1dad0932014-03-31 15:24:08 +0200797 if (register_external_irq(EXT_IRQ_EXTERNAL_CALL, do_ext_call_interrupt))
Martin Schwidefskyd98e19c2011-10-30 15:16:58 +0100798 panic("Couldn't request external interrupt 0x1202");
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400799 smp_detect_cpus();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800}
801
Heiko Carstensea1f4ee2007-05-31 17:38:05 +0200802void __init smp_prepare_boot_cpu(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400804 struct pcpu *pcpu = pcpu_devices;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400806 boot_cpu_address = stap();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400807 pcpu->state = CPU_STATE_CONFIGURED;
808 pcpu->address = boot_cpu_address;
809 pcpu->lowcore = (struct _lowcore *)(unsigned long) store_prefix();
Martin Schwidefskydc7ee002013-04-24 10:20:43 +0200810 pcpu->async_stack = S390_lowcore.async_stack - ASYNC_SIZE
811 + STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
812 pcpu->panic_stack = S390_lowcore.panic_stack - PAGE_SIZE
813 + STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400814 S390_lowcore.percpu_offset = __per_cpu_offset[0];
Heiko Carstens50ab9a92012-09-04 17:36:16 +0200815 smp_cpu_set_polarization(0, POLARIZATION_UNKNOWN);
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +0200816 set_cpu_present(0, true);
817 set_cpu_online(0, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
Heiko Carstensea1f4ee2007-05-31 17:38:05 +0200820void __init smp_cpus_done(unsigned int max_cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822}
823
Heiko Carstens02beacc2010-01-13 20:44:34 +0100824void __init smp_setup_processor_id(void)
825{
826 S390_lowcore.cpu_nr = 0;
Heiko Carstens02beacc2010-01-13 20:44:34 +0100827}
828
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829/*
830 * the frequency of the profiling timer can be changed
831 * by writing a multiplier value into /proc/profile.
832 *
833 * usually you want to run this on all CPUs ;)
834 */
835int setup_profiling_timer(unsigned int multiplier)
836{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200837 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838}
839
Heiko Carstens08d07962008-01-26 14:10:56 +0100840#ifdef CONFIG_HOTPLUG_CPU
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800841static ssize_t cpu_configure_show(struct device *dev,
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400842 struct device_attribute *attr, char *buf)
Heiko Carstens08d07962008-01-26 14:10:56 +0100843{
844 ssize_t count;
845
846 mutex_lock(&smp_cpu_state_mutex);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400847 count = sprintf(buf, "%d\n", pcpu_devices[dev->id].state);
Heiko Carstens08d07962008-01-26 14:10:56 +0100848 mutex_unlock(&smp_cpu_state_mutex);
849 return count;
850}
851
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800852static ssize_t cpu_configure_store(struct device *dev,
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400853 struct device_attribute *attr,
854 const char *buf, size_t count)
Heiko Carstens08d07962008-01-26 14:10:56 +0100855{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400856 struct pcpu *pcpu;
857 int cpu, val, rc;
Heiko Carstens08d07962008-01-26 14:10:56 +0100858 char delim;
859
860 if (sscanf(buf, "%d %c", &val, &delim) != 1)
861 return -EINVAL;
862 if (val != 0 && val != 1)
863 return -EINVAL;
Martin Schwidefsky9d40d2e2008-01-26 14:11:31 +0100864 get_online_cpus();
Heiko Carstens0b18d312008-04-30 13:38:36 +0200865 mutex_lock(&smp_cpu_state_mutex);
Heiko Carstens08d07962008-01-26 14:10:56 +0100866 rc = -EBUSY;
Heiko Carstens2c2df112010-02-26 22:37:34 +0100867 /* disallow configuration changes of online cpus and cpu 0 */
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400868 cpu = dev->id;
Heiko Carstens2c2df112010-02-26 22:37:34 +0100869 if (cpu_online(cpu) || cpu == 0)
Heiko Carstens08d07962008-01-26 14:10:56 +0100870 goto out;
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400871 pcpu = pcpu_devices + cpu;
Heiko Carstens08d07962008-01-26 14:10:56 +0100872 rc = 0;
873 switch (val) {
874 case 0:
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400875 if (pcpu->state != CPU_STATE_CONFIGURED)
876 break;
877 rc = sclp_cpu_deconfigure(pcpu->address);
878 if (rc)
879 break;
880 pcpu->state = CPU_STATE_STANDBY;
Heiko Carstens50ab9a92012-09-04 17:36:16 +0200881 smp_cpu_set_polarization(cpu, POLARIZATION_UNKNOWN);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400882 topology_expect_change();
Heiko Carstens08d07962008-01-26 14:10:56 +0100883 break;
884 case 1:
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400885 if (pcpu->state != CPU_STATE_STANDBY)
886 break;
887 rc = sclp_cpu_configure(pcpu->address);
888 if (rc)
889 break;
890 pcpu->state = CPU_STATE_CONFIGURED;
Heiko Carstens50ab9a92012-09-04 17:36:16 +0200891 smp_cpu_set_polarization(cpu, POLARIZATION_UNKNOWN);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400892 topology_expect_change();
Heiko Carstens08d07962008-01-26 14:10:56 +0100893 break;
894 default:
895 break;
896 }
897out:
Heiko Carstens08d07962008-01-26 14:10:56 +0100898 mutex_unlock(&smp_cpu_state_mutex);
Heiko Carstens0b18d312008-04-30 13:38:36 +0200899 put_online_cpus();
Heiko Carstens08d07962008-01-26 14:10:56 +0100900 return rc ? rc : count;
901}
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800902static DEVICE_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store);
Heiko Carstens08d07962008-01-26 14:10:56 +0100903#endif /* CONFIG_HOTPLUG_CPU */
904
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800905static ssize_t show_cpu_address(struct device *dev,
906 struct device_attribute *attr, char *buf)
Heiko Carstens08d07962008-01-26 14:10:56 +0100907{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400908 return sprintf(buf, "%d\n", pcpu_devices[dev->id].address);
Heiko Carstens08d07962008-01-26 14:10:56 +0100909}
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800910static DEVICE_ATTR(address, 0444, show_cpu_address, NULL);
Heiko Carstens08d07962008-01-26 14:10:56 +0100911
Heiko Carstens08d07962008-01-26 14:10:56 +0100912static struct attribute *cpu_common_attrs[] = {
913#ifdef CONFIG_HOTPLUG_CPU
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800914 &dev_attr_configure.attr,
Heiko Carstens08d07962008-01-26 14:10:56 +0100915#endif
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800916 &dev_attr_address.attr,
Heiko Carstens08d07962008-01-26 14:10:56 +0100917 NULL,
918};
919
920static struct attribute_group cpu_common_attr_group = {
921 .attrs = cpu_common_attrs,
922};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800924static ssize_t show_idle_count(struct device *dev,
925 struct device_attribute *attr, char *buf)
Heiko Carstensfae8b222007-10-22 12:52:39 +0200926{
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400927 struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
Heiko Carstensfae8b222007-10-22 12:52:39 +0200928 unsigned long long idle_count;
Martin Schwidefskye98bbaa2009-06-22 12:08:20 +0200929 unsigned int sequence;
Heiko Carstensfae8b222007-10-22 12:52:39 +0200930
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400931 do {
932 sequence = ACCESS_ONCE(idle->sequence);
933 idle_count = ACCESS_ONCE(idle->idle_count);
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200934 if (ACCESS_ONCE(idle->clock_idle_enter))
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400935 idle_count++;
Martin Schwidefsky4560e7c2013-10-28 12:15:32 +0100936 } while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
Heiko Carstensfae8b222007-10-22 12:52:39 +0200937 return sprintf(buf, "%llu\n", idle_count);
938}
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800939static DEVICE_ATTR(idle_count, 0444, show_idle_count, NULL);
Heiko Carstensfae8b222007-10-22 12:52:39 +0200940
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800941static ssize_t show_idle_time(struct device *dev,
942 struct device_attribute *attr, char *buf)
Heiko Carstensfae8b222007-10-22 12:52:39 +0200943{
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400944 struct s390_idle_data *idle = &per_cpu(s390_idle, dev->id);
945 unsigned long long now, idle_time, idle_enter, idle_exit;
Martin Schwidefskye98bbaa2009-06-22 12:08:20 +0200946 unsigned int sequence;
Heiko Carstensfae8b222007-10-22 12:52:39 +0200947
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400948 do {
Heiko Carstens1aae0562013-01-30 09:49:40 +0100949 now = get_tod_clock();
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400950 sequence = ACCESS_ONCE(idle->sequence);
951 idle_time = ACCESS_ONCE(idle->idle_time);
Martin Schwidefsky27f6b412012-07-20 11:15:08 +0200952 idle_enter = ACCESS_ONCE(idle->clock_idle_enter);
953 idle_exit = ACCESS_ONCE(idle->clock_idle_exit);
Martin Schwidefsky4560e7c2013-10-28 12:15:32 +0100954 } while ((sequence & 1) || (ACCESS_ONCE(idle->sequence) != sequence));
Martin Schwidefsky4c1051e2012-03-11 11:59:27 -0400955 idle_time += idle_enter ? ((idle_exit ? : now) - idle_enter) : 0;
Martin Schwidefsky6f430922008-12-31 15:11:40 +0100956 return sprintf(buf, "%llu\n", idle_time >> 12);
Heiko Carstensfae8b222007-10-22 12:52:39 +0200957}
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800958static DEVICE_ATTR(idle_time_us, 0444, show_idle_time, NULL);
Heiko Carstensfae8b222007-10-22 12:52:39 +0200959
Heiko Carstens08d07962008-01-26 14:10:56 +0100960static struct attribute *cpu_online_attrs[] = {
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800961 &dev_attr_idle_count.attr,
962 &dev_attr_idle_time_us.attr,
Heiko Carstensfae8b222007-10-22 12:52:39 +0200963 NULL,
964};
965
Heiko Carstens08d07962008-01-26 14:10:56 +0100966static struct attribute_group cpu_online_attr_group = {
967 .attrs = cpu_online_attrs,
Heiko Carstensfae8b222007-10-22 12:52:39 +0200968};
969
Paul Gortmakere2741f12013-06-18 17:04:52 -0400970static int smp_cpu_notify(struct notifier_block *self, unsigned long action,
971 void *hcpu)
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200972{
973 unsigned int cpu = (unsigned int)(long)hcpu;
Heiko Carstens96619fc2013-12-05 12:42:09 +0100974 struct cpu *c = pcpu_devices[cpu].cpu;
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800975 struct device *s = &c->dev;
Akinobu Mitad882ba62010-05-26 14:43:34 -0700976 int err = 0;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200977
Heiko Carstens1c725922012-08-27 15:43:49 +0200978 switch (action & ~CPU_TASKS_FROZEN) {
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200979 case CPU_ONLINE:
Akinobu Mitad882ba62010-05-26 14:43:34 -0700980 err = sysfs_create_group(&s->kobj, &cpu_online_attr_group);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200981 break;
982 case CPU_DEAD:
Heiko Carstens08d07962008-01-26 14:10:56 +0100983 sysfs_remove_group(&s->kobj, &cpu_online_attr_group);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200984 break;
985 }
Akinobu Mitad882ba62010-05-26 14:43:34 -0700986 return notifier_from_errno(err);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200987}
988
Paul Gortmakere2741f12013-06-18 17:04:52 -0400989static int smp_add_present_cpu(int cpu)
Heiko Carstens08d07962008-01-26 14:10:56 +0100990{
Heiko Carstens96619fc2013-12-05 12:42:09 +0100991 struct device *s;
992 struct cpu *c;
Heiko Carstens08d07962008-01-26 14:10:56 +0100993 int rc;
994
Heiko Carstens96619fc2013-12-05 12:42:09 +0100995 c = kzalloc(sizeof(*c), GFP_KERNEL);
996 if (!c)
997 return -ENOMEM;
998 pcpu_devices[cpu].cpu = c;
999 s = &c->dev;
Heiko Carstens08d07962008-01-26 14:10:56 +01001000 c->hotpluggable = 1;
1001 rc = register_cpu(c, cpu);
1002 if (rc)
1003 goto out;
1004 rc = sysfs_create_group(&s->kobj, &cpu_common_attr_group);
1005 if (rc)
1006 goto out_cpu;
Heiko Carstens83a24e32011-12-27 11:27:09 +01001007 if (cpu_online(cpu)) {
1008 rc = sysfs_create_group(&s->kobj, &cpu_online_attr_group);
1009 if (rc)
1010 goto out_online;
1011 }
1012 rc = topology_cpu_init(c);
1013 if (rc)
1014 goto out_topology;
1015 return 0;
1016
1017out_topology:
1018 if (cpu_online(cpu))
1019 sysfs_remove_group(&s->kobj, &cpu_online_attr_group);
1020out_online:
Heiko Carstens08d07962008-01-26 14:10:56 +01001021 sysfs_remove_group(&s->kobj, &cpu_common_attr_group);
1022out_cpu:
1023#ifdef CONFIG_HOTPLUG_CPU
1024 unregister_cpu(c);
1025#endif
1026out:
1027 return rc;
1028}
1029
1030#ifdef CONFIG_HOTPLUG_CPU
Heiko Carstens1e489512008-04-30 13:38:37 +02001031
Heiko Carstens67060d92008-05-30 10:03:27 +02001032int __ref smp_rescan_cpus(void)
Heiko Carstens08d07962008-01-26 14:10:56 +01001033{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001034 struct sclp_cpu_info *info;
1035 int nr;
Heiko Carstens08d07962008-01-26 14:10:56 +01001036
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001037 info = smp_get_cpu_info();
1038 if (!info)
1039 return -ENOMEM;
Martin Schwidefsky9d40d2e2008-01-26 14:11:31 +01001040 get_online_cpus();
Heiko Carstens0b18d312008-04-30 13:38:36 +02001041 mutex_lock(&smp_cpu_state_mutex);
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001042 nr = __smp_rescan_cpus(info, 1);
Heiko Carstens08d07962008-01-26 14:10:56 +01001043 mutex_unlock(&smp_cpu_state_mutex);
Heiko Carstens0b18d312008-04-30 13:38:36 +02001044 put_online_cpus();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001045 kfree(info);
1046 if (nr)
Heiko Carstensc10fde02008-04-17 07:46:13 +02001047 topology_schedule_update();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001048 return 0;
Heiko Carstens1e489512008-04-30 13:38:37 +02001049}
1050
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001051static ssize_t __ref rescan_store(struct device *dev,
1052 struct device_attribute *attr,
Andi Kleenc9be0a32010-01-05 12:47:58 +01001053 const char *buf,
Heiko Carstens1e489512008-04-30 13:38:37 +02001054 size_t count)
1055{
1056 int rc;
1057
1058 rc = smp_rescan_cpus();
Heiko Carstens08d07962008-01-26 14:10:56 +01001059 return rc ? rc : count;
1060}
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001061static DEVICE_ATTR(rescan, 0200, NULL, rescan_store);
Heiko Carstens08d07962008-01-26 14:10:56 +01001062#endif /* CONFIG_HOTPLUG_CPU */
1063
Heiko Carstens83a24e32011-12-27 11:27:09 +01001064static int __init s390_smp_init(void)
Heiko Carstensc10fde02008-04-17 07:46:13 +02001065{
Srivatsa S. Bhatf4edbcd2014-03-11 02:05:58 +05301066 int cpu, rc = 0;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02001067
Heiko Carstens08d07962008-01-26 14:10:56 +01001068#ifdef CONFIG_HOTPLUG_CPU
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001069 rc = device_create_file(cpu_subsys.dev_root, &dev_attr_rescan);
Heiko Carstens08d07962008-01-26 14:10:56 +01001070 if (rc)
1071 return rc;
1072#endif
Srivatsa S. Bhatf4edbcd2014-03-11 02:05:58 +05301073 cpu_notifier_register_begin();
Heiko Carstens08d07962008-01-26 14:10:56 +01001074 for_each_present_cpu(cpu) {
1075 rc = smp_add_present_cpu(cpu);
Heiko Carstensfae8b222007-10-22 12:52:39 +02001076 if (rc)
Srivatsa S. Bhatf4edbcd2014-03-11 02:05:58 +05301077 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 }
Srivatsa S. Bhatf4edbcd2014-03-11 02:05:58 +05301079
1080 __hotcpu_notifier(smp_cpu_notify, 0);
1081
1082out:
1083 cpu_notifier_register_done();
1084 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085}
Heiko Carstens83a24e32011-12-27 11:27:09 +01001086subsys_initcall(s390_smp_init);