blob: 3bde5688ceb50820c2b232de87008169ec549332 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/kernel/smp.c
3 *
Hans-Joachim Picht155af2f2009-06-16 10:30:52 +02004 * Copyright IBM Corp. 1999, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
Heiko Carstens39ce0102007-04-27 16:02:00 +02006 * 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 *
13 * We work with logical cpu numbering everywhere we can. The only
14 * functions using the real cpu address (got from STAP) are the sigp
15 * functions. For all other functions we use the identity mapping.
16 * That means that cpu_number_map[i] == i for every cpu. cpu_number_map is
17 * used e.g. to find the idle task belonging to a logical cpu. Every array
18 * in the kernel is sorted by the logical cpu number and not by the physical
19 * one which is causing all the confusion with __cpu_logical_map and
20 * cpu_number_map in other architectures.
21 */
22
Martin Schwidefsky395d31d2008-12-25 13:39:50 +010023#define KMSG_COMPONENT "cpu"
24#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
25
Heiko Carstensf2308862011-01-05 12:48:08 +010026#include <linux/workqueue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/module.h>
28#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/mm.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040030#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/spinlock.h>
32#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/delay.h>
34#include <linux/cache.h>
35#include <linux/interrupt.h>
Christian Borntraeger3324e602009-03-26 15:23:56 +010036#include <linux/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/cpu.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010038#include <linux/timex.h>
Michael Holzheu411ed322007-04-27 16:01:49 +020039#include <linux/bootmem.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090040#include <linux/slab.h>
Michael Holzheu60a0c682011-10-30 15:16:40 +010041#include <linux/crash_dump.h>
Heiko Carstenscbb870c2010-02-26 22:37:43 +010042#include <asm/asm-offsets.h>
Michael Holzheu46b05d22007-02-21 10:55:21 +010043#include <asm/ipl.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010044#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <asm/sigp.h>
46#include <asm/pgalloc.h>
47#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <asm/cpcmd.h>
49#include <asm/tlbflush.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010050#include <asm/timer.h>
Michael Holzheu411ed322007-04-27 16:01:49 +020051#include <asm/lowcore.h>
Heiko Carstens08d07962008-01-26 14:10:56 +010052#include <asm/sclp.h>
Martin Schwidefsky76d4e002009-06-12 10:26:21 +020053#include <asm/cputime.h>
Martin Schwidefskyc742b312008-12-31 15:11:42 +010054#include <asm/vdso.h>
Heiko Carstens4bb5e072009-09-11 10:29:03 +020055#include <asm/cpu.h>
Heiko Carstensa8061702008-04-17 07:46:26 +020056#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Heiko Carstensfb380aa2010-01-13 20:44:37 +010058/* logical cpu to cpu address */
Heiko Carstensa93b8ec2010-02-26 22:37:35 +010059unsigned short __cpu_logical_map[NR_CPUS];
Heiko Carstensfb380aa2010-01-13 20:44:37 +010060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061static struct task_struct *current_set[NR_CPUS];
62
Heiko Carstens08d07962008-01-26 14:10:56 +010063static u8 smp_cpu_type;
64static int smp_use_sigp_detection;
65
66enum s390_cpu_state {
67 CPU_STATE_STANDBY,
68 CPU_STATE_CONFIGURED,
69};
70
Heiko Carstensdbd70fb2008-04-17 07:46:12 +020071DEFINE_MUTEX(smp_cpu_state_mutex);
Heiko Carstensc10fde02008-04-17 07:46:13 +020072int smp_cpu_polarization[NR_CPUS];
Heiko Carstens08d07962008-01-26 14:10:56 +010073static int smp_cpu_state[NR_CPUS];
Heiko Carstensc10fde02008-04-17 07:46:13 +020074static int cpu_management;
Heiko Carstens08d07962008-01-26 14:10:56 +010075
76static DEFINE_PER_CPU(struct cpu, cpu_devices);
Heiko Carstens08d07962008-01-26 14:10:56 +010077
Heiko Carstensa93b8ec2010-02-26 22:37:35 +010078static void smp_ext_bitcall(int, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Heiko Carstensa93b8ec2010-02-26 22:37:35 +010080static int raw_cpu_stopped(int cpu)
Heiko Carstens5c0b9122009-09-11 10:29:05 +020081{
Heiko Carstensa93b8ec2010-02-26 22:37:35 +010082 u32 status;
Heiko Carstens5c0b9122009-09-11 10:29:05 +020083
Heiko Carstensa93b8ec2010-02-26 22:37:35 +010084 switch (raw_sigp_ps(&status, 0, cpu, sigp_sense)) {
Heiko Carstens5c0b9122009-09-11 10:29:05 +020085 case sigp_status_stored:
86 /* Check for stopped and check stop state */
87 if (status & 0x50)
88 return 1;
89 break;
90 default:
91 break;
92 }
93 return 0;
94}
95
Heiko Carstensa93b8ec2010-02-26 22:37:35 +010096static inline int cpu_stopped(int cpu)
97{
98 return raw_cpu_stopped(cpu_logical_map(cpu));
99}
100
Michael Holzheu1943f532011-10-30 15:16:38 +0100101/*
102 * Ensure that PSW restart is done on an online CPU
103 */
104void smp_restart_with_online_cpu(void)
105{
106 int cpu;
107
108 for_each_online_cpu(cpu) {
109 if (stap() == __cpu_logical_map[cpu]) {
110 /* We are online: Enable DAT again and return */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100111 __load_psw_mask(psw_kernel_bits | PSW_MASK_DAT);
Michael Holzheu1943f532011-10-30 15:16:38 +0100112 return;
113 }
114 }
115 /* We are not online: Do PSW restart on an online CPU */
116 while (sigp(cpu, sigp_restart) == sigp_busy)
117 cpu_relax();
118 /* And stop ourself */
119 while (raw_sigp(stap(), sigp_stop) == sigp_busy)
120 cpu_relax();
121 for (;;);
122}
123
Heiko Carstens2c2df112010-02-26 22:37:34 +0100124void smp_switch_to_ipl_cpu(void (*func)(void *), void *data)
125{
126 struct _lowcore *lc, *current_lc;
127 struct stack_frame *sf;
128 struct pt_regs *regs;
129 unsigned long sp;
130
131 if (smp_processor_id() == 0)
132 func(data);
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100133 __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE |
134 PSW_MASK_EA | PSW_MASK_BA);
Heiko Carstens2c2df112010-02-26 22:37:34 +0100135 /* Disable lowcore protection */
136 __ctl_clear_bit(0, 28);
137 current_lc = lowcore_ptr[smp_processor_id()];
138 lc = lowcore_ptr[0];
139 if (!lc)
140 lc = current_lc;
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100141 lc->restart_psw.mask =
142 PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA;
Heiko Carstens2c2df112010-02-26 22:37:34 +0100143 lc->restart_psw.addr = PSW_ADDR_AMODE | (unsigned long) smp_restart_cpu;
144 if (!cpu_online(0))
145 smp_switch_to_cpu(func, data, 0, stap(), __cpu_logical_map[0]);
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100146 while (sigp(0, sigp_stop_and_store_status) == sigp_busy)
Heiko Carstens2c2df112010-02-26 22:37:34 +0100147 cpu_relax();
148 sp = lc->panic_stack;
149 sp -= sizeof(struct pt_regs);
150 regs = (struct pt_regs *) sp;
151 memcpy(&regs->gprs, &current_lc->gpregs_save_area, sizeof(regs->gprs));
Heiko Carstenscbb870c2010-02-26 22:37:43 +0100152 regs->psw = lc->psw_save_area;
Heiko Carstens2c2df112010-02-26 22:37:34 +0100153 sp -= STACK_FRAME_OVERHEAD;
154 sf = (struct stack_frame *) sp;
155 sf->back_chain = regs->gprs[15];
156 smp_switch_to_cpu(func, data, sp, stap(), __cpu_logical_map[0]);
157}
158
Heiko Carstens677d7622007-11-20 11:13:37 +0100159void smp_send_stop(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200161 int cpu, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Heiko Carstens677d7622007-11-20 11:13:37 +0100163 /* Disable all interrupts/machine checks */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100164 __load_psw_mask(psw_kernel_bits | PSW_MASK_DAT);
Christian Borntraeger3324e602009-03-26 15:23:56 +0100165 trace_hardirqs_off();
Heiko Carstens677d7622007-11-20 11:13:37 +0100166
Heiko Carstens39ce0102007-04-27 16:02:00 +0200167 /* stop all processors */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 for_each_online_cpu(cpu) {
169 if (cpu == smp_processor_id())
170 continue;
171 do {
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100172 rc = sigp(cpu, sigp_stop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 } while (rc == sigp_busy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Heiko Carstens5c0b9122009-09-11 10:29:05 +0200175 while (!cpu_stopped(cpu))
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100176 cpu_relax();
177 }
178}
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 * This is the main routine where commands issued by other
182 * cpus are handled.
183 */
184
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200185static void do_ext_call_interrupt(unsigned int ext_int_code,
186 unsigned int param32, unsigned long param64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200188 unsigned long bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Heiko Carstens052ff462011-01-05 12:47:28 +0100190 kstat_cpu(smp_processor_id()).irqs[EXTINT_IPI]++;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200191 /*
192 * handle bit signal external calls
Heiko Carstens39ce0102007-04-27 16:02:00 +0200193 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 bits = xchg(&S390_lowcore.ext_call_fast, 0);
195
Peter Zijlstra184748c2011-04-05 17:23:39 +0200196 if (test_bit(ec_schedule, &bits))
197 scheduler_ipi();
198
Heiko Carstens39ce0102007-04-27 16:02:00 +0200199 if (test_bit(ec_call_function, &bits))
Heiko Carstensca9fc752008-12-25 13:38:39 +0100200 generic_smp_call_function_interrupt();
201
202 if (test_bit(ec_call_function_single, &bits))
203 generic_smp_call_function_single_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
206/*
207 * Send an external call sigp to another cpu and return without waiting
208 * for its completion.
209 */
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100210static void smp_ext_bitcall(int cpu, int sig)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Martin Schwidefskyd98e19c2011-10-30 15:16:58 +0100212 int order;
213
Heiko Carstens39ce0102007-04-27 16:02:00 +0200214 /*
215 * Set signaling bit in lowcore of target cpu and kick it
216 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast);
Martin Schwidefskyd98e19c2011-10-30 15:16:58 +0100218 while (1) {
219 order = smp_vcpu_scheduled(cpu) ?
220 sigp_external_call : sigp_emergency_signal;
221 if (sigp(cpu, order) != sigp_busy)
222 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 udelay(10);
Martin Schwidefskyd98e19c2011-10-30 15:16:58 +0100224 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
Rusty Russell630cd042009-09-24 09:34:45 -0600227void arch_send_call_function_ipi_mask(const struct cpumask *mask)
Heiko Carstensca9fc752008-12-25 13:38:39 +0100228{
229 int cpu;
230
Rusty Russell630cd042009-09-24 09:34:45 -0600231 for_each_cpu(cpu, mask)
Heiko Carstensca9fc752008-12-25 13:38:39 +0100232 smp_ext_bitcall(cpu, ec_call_function);
233}
234
235void arch_send_call_function_single_ipi(int cpu)
236{
237 smp_ext_bitcall(cpu, ec_call_function_single);
238}
239
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800240#ifndef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241/*
242 * this function sends a 'purge tlb' signal to another CPU.
243 */
Heiko Carstensa8061702008-04-17 07:46:26 +0200244static void smp_ptlb_callback(void *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200246 __tlb_flush_local();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
249void smp_ptlb_all(void)
250{
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200251 on_each_cpu(smp_ptlb_callback, NULL, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252}
253EXPORT_SYMBOL(smp_ptlb_all);
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800254#endif /* ! CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256/*
257 * this function sends a 'reschedule' IPI to another CPU.
258 * it goes straight through and wastes no time serializing
259 * anything. Worst case is that we lose a reschedule ...
260 */
261void smp_send_reschedule(int cpu)
262{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200263 smp_ext_bitcall(cpu, ec_schedule);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264}
265
266/*
267 * parameter area for the set/clear control bit callbacks
268 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200269struct ec_creg_mask_parms {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 unsigned long orvals[16];
271 unsigned long andvals[16];
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200272};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274/*
275 * callback for setting/clearing control bits
276 */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200277static void smp_ctl_bit_callback(void *info)
278{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200279 struct ec_creg_mask_parms *pp = info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 unsigned long cregs[16];
281 int i;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200282
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200283 __ctl_store(cregs, 0, 15);
284 for (i = 0; i <= 15; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 cregs[i] = (cregs[i] & pp->andvals[i]) | pp->orvals[i];
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200286 __ctl_load(cregs, 0, 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288
289/*
290 * Set a bit in a control register of all cpus
291 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200292void smp_ctl_set_bit(int cr, int bit)
293{
294 struct ec_creg_mask_parms parms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200296 memset(&parms.orvals, 0, sizeof(parms.orvals));
297 memset(&parms.andvals, 0xff, sizeof(parms.andvals));
Jan Glauber859c9652011-06-22 16:24:10 +0200298 parms.orvals[cr] = 1UL << bit;
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200299 on_each_cpu(smp_ctl_bit_callback, &parms, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300}
Heiko Carstens39ce0102007-04-27 16:02:00 +0200301EXPORT_SYMBOL(smp_ctl_set_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303/*
304 * Clear a bit in a control register of all cpus
305 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200306void smp_ctl_clear_bit(int cr, int bit)
307{
308 struct ec_creg_mask_parms parms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200310 memset(&parms.orvals, 0, sizeof(parms.orvals));
311 memset(&parms.andvals, 0xff, sizeof(parms.andvals));
Jan Glauber859c9652011-06-22 16:24:10 +0200312 parms.andvals[cr] = ~(1UL << bit);
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200313 on_each_cpu(smp_ctl_bit_callback, &parms, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
Heiko Carstens39ce0102007-04-27 16:02:00 +0200315EXPORT_SYMBOL(smp_ctl_clear_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Michael Holzheu60a0c682011-10-30 15:16:40 +0100317#if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_CRASH_DUMP)
Michael Holzheu411ed322007-04-27 16:01:49 +0200318
Heiko Carstens285f6722007-07-10 11:24:13 +0200319static void __init smp_get_save_area(unsigned int cpu, unsigned int phy_cpu)
Michael Holzheu411ed322007-04-27 16:01:49 +0200320{
Michael Holzheu60a0c682011-10-30 15:16:40 +0100321 if (ipl_info.type != IPL_TYPE_FCP_DUMP && !OLDMEM_BASE)
322 return;
323 if (is_kdump_kernel())
Michael Holzheu411ed322007-04-27 16:01:49 +0200324 return;
Heiko Carstens285f6722007-07-10 11:24:13 +0200325 if (cpu >= NR_CPUS) {
Martin Schwidefsky395d31d2008-12-25 13:39:50 +0100326 pr_warning("CPU %i exceeds the maximum %i and is excluded from "
327 "the dump\n", cpu, NR_CPUS - 1);
Heiko Carstens285f6722007-07-10 11:24:13 +0200328 return;
Michael Holzheu411ed322007-04-27 16:01:49 +0200329 }
Heiko Carstensf64ca212010-02-26 22:37:32 +0100330 zfcpdump_save_areas[cpu] = kmalloc(sizeof(struct save_area), GFP_KERNEL);
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100331 while (raw_sigp(phy_cpu, sigp_stop_and_store_status) == sigp_busy)
Heiko Carstens285f6722007-07-10 11:24:13 +0200332 cpu_relax();
Michael Holzheu92fe3132010-03-24 11:49:50 +0100333 memcpy_real(zfcpdump_save_areas[cpu],
334 (void *)(unsigned long) store_prefix() + SAVE_AREA_BASE,
335 sizeof(struct save_area));
Michael Holzheu411ed322007-04-27 16:01:49 +0200336}
337
Heiko Carstensf64ca212010-02-26 22:37:32 +0100338struct save_area *zfcpdump_save_areas[NR_CPUS + 1];
Michael Holzheu411ed322007-04-27 16:01:49 +0200339EXPORT_SYMBOL_GPL(zfcpdump_save_areas);
340
341#else
Heiko Carstens285f6722007-07-10 11:24:13 +0200342
343static inline void smp_get_save_area(unsigned int cpu, unsigned int phy_cpu) { }
344
Michael Holzheu59f2e692009-03-26 15:24:46 +0100345#endif /* CONFIG_ZFCPDUMP */
Michael Holzheu411ed322007-04-27 16:01:49 +0200346
Heiko Carstens08d07962008-01-26 14:10:56 +0100347static int cpu_known(int cpu_id)
348{
349 int cpu;
350
351 for_each_present_cpu(cpu) {
352 if (__cpu_logical_map[cpu] == cpu_id)
353 return 1;
354 }
355 return 0;
356}
357
358static int smp_rescan_cpus_sigp(cpumask_t avail)
359{
360 int cpu_id, logical_cpu;
361
Rusty Russell93632d12009-03-26 15:24:59 +0100362 logical_cpu = cpumask_first(&avail);
363 if (logical_cpu >= nr_cpu_ids)
Heiko Carstens08d07962008-01-26 14:10:56 +0100364 return 0;
Heiko Carstens4bb5e072009-09-11 10:29:03 +0200365 for (cpu_id = 0; cpu_id <= MAX_CPU_ADDRESS; cpu_id++) {
Heiko Carstens08d07962008-01-26 14:10:56 +0100366 if (cpu_known(cpu_id))
367 continue;
368 __cpu_logical_map[logical_cpu] = cpu_id;
Heiko Carstensc10fde02008-04-17 07:46:13 +0200369 smp_cpu_polarization[logical_cpu] = POLARIZATION_UNKNWN;
Heiko Carstens08d07962008-01-26 14:10:56 +0100370 if (!cpu_stopped(logical_cpu))
371 continue;
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +0200372 set_cpu_present(logical_cpu, true);
Heiko Carstens08d07962008-01-26 14:10:56 +0100373 smp_cpu_state[logical_cpu] = CPU_STATE_CONFIGURED;
Rusty Russell93632d12009-03-26 15:24:59 +0100374 logical_cpu = cpumask_next(logical_cpu, &avail);
375 if (logical_cpu >= nr_cpu_ids)
Heiko Carstens08d07962008-01-26 14:10:56 +0100376 break;
377 }
378 return 0;
379}
380
Heiko Carstens48483b32008-01-26 14:11:05 +0100381static int smp_rescan_cpus_sclp(cpumask_t avail)
Heiko Carstens08d07962008-01-26 14:10:56 +0100382{
383 struct sclp_cpu_info *info;
384 int cpu_id, logical_cpu, cpu;
385 int rc;
386
Rusty Russell93632d12009-03-26 15:24:59 +0100387 logical_cpu = cpumask_first(&avail);
388 if (logical_cpu >= nr_cpu_ids)
Heiko Carstens08d07962008-01-26 14:10:56 +0100389 return 0;
Heiko Carstens48483b32008-01-26 14:11:05 +0100390 info = kmalloc(sizeof(*info), GFP_KERNEL);
Heiko Carstens08d07962008-01-26 14:10:56 +0100391 if (!info)
392 return -ENOMEM;
393 rc = sclp_get_cpu_info(info);
394 if (rc)
395 goto out;
396 for (cpu = 0; cpu < info->combined; cpu++) {
397 if (info->has_cpu_type && info->cpu[cpu].type != smp_cpu_type)
398 continue;
399 cpu_id = info->cpu[cpu].address;
400 if (cpu_known(cpu_id))
401 continue;
402 __cpu_logical_map[logical_cpu] = cpu_id;
Heiko Carstensc10fde02008-04-17 07:46:13 +0200403 smp_cpu_polarization[logical_cpu] = POLARIZATION_UNKNWN;
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +0200404 set_cpu_present(logical_cpu, true);
Heiko Carstens08d07962008-01-26 14:10:56 +0100405 if (cpu >= info->configured)
406 smp_cpu_state[logical_cpu] = CPU_STATE_STANDBY;
407 else
408 smp_cpu_state[logical_cpu] = CPU_STATE_CONFIGURED;
Rusty Russell93632d12009-03-26 15:24:59 +0100409 logical_cpu = cpumask_next(logical_cpu, &avail);
410 if (logical_cpu >= nr_cpu_ids)
Heiko Carstens08d07962008-01-26 14:10:56 +0100411 break;
412 }
413out:
Heiko Carstens48483b32008-01-26 14:11:05 +0100414 kfree(info);
Heiko Carstens08d07962008-01-26 14:10:56 +0100415 return rc;
416}
417
Heiko Carstens1e489512008-04-30 13:38:37 +0200418static int __smp_rescan_cpus(void)
Heiko Carstens08d07962008-01-26 14:10:56 +0100419{
420 cpumask_t avail;
421
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +0200422 cpumask_xor(&avail, cpu_possible_mask, cpu_present_mask);
Heiko Carstens08d07962008-01-26 14:10:56 +0100423 if (smp_use_sigp_detection)
424 return smp_rescan_cpus_sigp(avail);
425 else
426 return smp_rescan_cpus_sclp(avail);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
Heiko Carstens48483b32008-01-26 14:11:05 +0100429static void __init smp_detect_cpus(void)
430{
431 unsigned int cpu, c_cpus, s_cpus;
432 struct sclp_cpu_info *info;
433 u16 boot_cpu_addr, cpu_addr;
434
435 c_cpus = 1;
436 s_cpus = 0;
Martin Schwidefsky7b468482009-03-26 15:24:42 +0100437 boot_cpu_addr = __cpu_logical_map[0];
Heiko Carstens48483b32008-01-26 14:11:05 +0100438 info = kmalloc(sizeof(*info), GFP_KERNEL);
439 if (!info)
440 panic("smp_detect_cpus failed to allocate memory\n");
Michael Holzheu60a0c682011-10-30 15:16:40 +0100441#ifdef CONFIG_CRASH_DUMP
442 if (OLDMEM_BASE && !is_kdump_kernel()) {
443 struct save_area *save_area;
444
445 save_area = kmalloc(sizeof(*save_area), GFP_KERNEL);
446 if (!save_area)
447 panic("could not allocate memory for save area\n");
448 copy_oldmem_page(1, (void *) save_area, sizeof(*save_area),
449 0x200, 0);
450 zfcpdump_save_areas[0] = save_area;
451 }
452#endif
Heiko Carstens48483b32008-01-26 14:11:05 +0100453 /* Use sigp detection algorithm if sclp doesn't work. */
454 if (sclp_get_cpu_info(info)) {
455 smp_use_sigp_detection = 1;
Heiko Carstens4bb5e072009-09-11 10:29:03 +0200456 for (cpu = 0; cpu <= MAX_CPU_ADDRESS; cpu++) {
Heiko Carstens48483b32008-01-26 14:11:05 +0100457 if (cpu == boot_cpu_addr)
458 continue;
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100459 if (!raw_cpu_stopped(cpu))
Heiko Carstens48483b32008-01-26 14:11:05 +0100460 continue;
461 smp_get_save_area(c_cpus, cpu);
462 c_cpus++;
463 }
464 goto out;
465 }
466
467 if (info->has_cpu_type) {
468 for (cpu = 0; cpu < info->combined; cpu++) {
469 if (info->cpu[cpu].address == boot_cpu_addr) {
470 smp_cpu_type = info->cpu[cpu].type;
471 break;
472 }
473 }
474 }
475
476 for (cpu = 0; cpu < info->combined; cpu++) {
477 if (info->has_cpu_type && info->cpu[cpu].type != smp_cpu_type)
478 continue;
479 cpu_addr = info->cpu[cpu].address;
480 if (cpu_addr == boot_cpu_addr)
481 continue;
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100482 if (!raw_cpu_stopped(cpu_addr)) {
Heiko Carstens48483b32008-01-26 14:11:05 +0100483 s_cpus++;
484 continue;
485 }
486 smp_get_save_area(c_cpus, cpu_addr);
487 c_cpus++;
488 }
489out:
490 kfree(info);
Martin Schwidefsky395d31d2008-12-25 13:39:50 +0100491 pr_info("%d configured CPUs, %d standby CPUs\n", c_cpus, s_cpus);
Martin Schwidefsky9d40d2e2008-01-26 14:11:31 +0100492 get_online_cpus();
Heiko Carstens1e489512008-04-30 13:38:37 +0200493 __smp_rescan_cpus();
Martin Schwidefsky9d40d2e2008-01-26 14:11:31 +0100494 put_online_cpus();
Heiko Carstens48483b32008-01-26 14:11:05 +0100495}
496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497/*
Heiko Carstens39ce0102007-04-27 16:02:00 +0200498 * Activate a secondary processor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 */
Heiko Carstensea1f4ee2007-05-31 17:38:05 +0200500int __cpuinit start_secondary(void *cpuvoid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200502 cpu_init();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800503 preempt_disable();
Heiko Carstens39ce0102007-04-27 16:02:00 +0200504 init_cpu_timer();
Heiko Carstens39ce0102007-04-27 16:02:00 +0200505 init_cpu_vtimer();
Heiko Carstens29b08d22006-12-04 15:40:40 +0100506 pfault_init();
507
Manfred Spraule545a612008-09-07 16:57:22 +0200508 notify_cpu_starting(smp_processor_id());
Heiko Carstensca9fc752008-12-25 13:38:39 +0100509 ipi_call_lock();
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +0200510 set_cpu_online(smp_processor_id(), true);
Heiko Carstensca9fc752008-12-25 13:38:39 +0100511 ipi_call_unlock();
Michael Holzheu7dd6b332011-08-03 16:44:19 +0200512 __ctl_clear_bit(0, 28); /* Disable lowcore protection */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100513 S390_lowcore.restart_psw.mask =
514 PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA;
Michael Holzheu7dd6b332011-08-03 16:44:19 +0200515 S390_lowcore.restart_psw.addr =
516 PSW_ADDR_AMODE | (unsigned long) psw_restart_int_handler;
517 __ctl_set_bit(0, 28); /* Enable lowcore protection */
Heiko Carstenscc343212011-08-03 16:44:27 +0200518 /*
519 * Wait until the cpu which brought this one up marked it
520 * active before enabling interrupts.
521 */
522 while (!cpumask_test_cpu(smp_processor_id(), cpu_active_mask))
523 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 local_irq_enable();
Heiko Carstens39ce0102007-04-27 16:02:00 +0200525 /* cpu_idle will call schedule for us */
526 cpu_idle();
527 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528}
529
Heiko Carstensf2308862011-01-05 12:48:08 +0100530struct create_idle {
531 struct work_struct work;
532 struct task_struct *idle;
533 struct completion done;
534 int cpu;
535};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Heiko Carstensf2308862011-01-05 12:48:08 +0100537static void __cpuinit smp_fork_idle(struct work_struct *work)
538{
539 struct create_idle *c_idle;
540
541 c_idle = container_of(work, struct create_idle, work);
542 c_idle->idle = fork_idle(c_idle->cpu);
543 complete(&c_idle->done);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544}
545
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100546static int __cpuinit smp_alloc_lowcore(int cpu)
547{
548 unsigned long async_stack, panic_stack;
549 struct _lowcore *lowcore;
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100550
Heiko Carstens3fd26a72009-09-22 22:58:49 +0200551 lowcore = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER);
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100552 if (!lowcore)
553 return -ENOMEM;
554 async_stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100555 panic_stack = __get_free_page(GFP_KERNEL);
Heiko Carstens591bb4f2008-02-19 15:29:29 +0100556 if (!panic_stack || !async_stack)
557 goto out;
Heiko Carstens98c7b382008-03-05 12:37:09 +0100558 memcpy(lowcore, &S390_lowcore, 512);
559 memset((char *)lowcore + 512, 0, sizeof(*lowcore) - 512);
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100560 lowcore->async_stack = async_stack + ASYNC_SIZE;
561 lowcore->panic_stack = panic_stack + PAGE_SIZE;
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100562 lowcore->restart_psw.mask =
563 PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA;
Michael Holzheu7dd6b332011-08-03 16:44:19 +0200564 lowcore->restart_psw.addr =
565 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
566 if (user_mode != HOME_SPACE_MODE)
567 lowcore->restart_psw.mask |= PSW_ASC_HOME;
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100568#ifndef CONFIG_64BIT
569 if (MACHINE_HAS_IEEE) {
570 unsigned long save_area;
571
572 save_area = get_zeroed_page(GFP_KERNEL);
573 if (!save_area)
Martin Schwidefsky33b1d092008-12-25 13:39:27 +0100574 goto out;
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100575 lowcore->extended_save_area_addr = (u32) save_area;
576 }
Martin Schwidefskyc742b312008-12-31 15:11:42 +0100577#else
578 if (vdso_alloc_per_cpu(cpu, lowcore))
579 goto out;
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100580#endif
581 lowcore_ptr[cpu] = lowcore;
582 return 0;
583
Heiko Carstens591bb4f2008-02-19 15:29:29 +0100584out:
Martin Schwidefsky33b1d092008-12-25 13:39:27 +0100585 free_page(panic_stack);
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100586 free_pages(async_stack, ASYNC_ORDER);
Heiko Carstens3fd26a72009-09-22 22:58:49 +0200587 free_pages((unsigned long) lowcore, LC_ORDER);
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100588 return -ENOMEM;
589}
590
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100591static void smp_free_lowcore(int cpu)
592{
593 struct _lowcore *lowcore;
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100594
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100595 lowcore = lowcore_ptr[cpu];
596#ifndef CONFIG_64BIT
597 if (MACHINE_HAS_IEEE)
598 free_page((unsigned long) lowcore->extended_save_area_addr);
Martin Schwidefskyc742b312008-12-31 15:11:42 +0100599#else
600 vdso_free_per_cpu(cpu, lowcore);
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100601#endif
602 free_page(lowcore->panic_stack - PAGE_SIZE);
603 free_pages(lowcore->async_stack - ASYNC_SIZE, ASYNC_ORDER);
Heiko Carstens3fd26a72009-09-22 22:58:49 +0200604 free_pages((unsigned long) lowcore, LC_ORDER);
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100605 lowcore_ptr[cpu] = NULL;
606}
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608/* Upping and downing of CPUs */
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100609int __cpuinit __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200611 struct _lowcore *cpu_lowcore;
Heiko Carstensf2308862011-01-05 12:48:08 +0100612 struct create_idle c_idle;
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100613 struct task_struct *idle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 struct stack_frame *sf;
Heiko Carstensd0d3cdf2009-03-26 15:24:53 +0100615 u32 lowcore;
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100616 int ccode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Heiko Carstens08d07962008-01-26 14:10:56 +0100618 if (smp_cpu_state[cpu] != CPU_STATE_CONFIGURED)
619 return -EIO;
Heiko Carstensf2308862011-01-05 12:48:08 +0100620 idle = current_set[cpu];
621 if (!idle) {
622 c_idle.done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done);
623 INIT_WORK_ONSTACK(&c_idle.work, smp_fork_idle);
624 c_idle.cpu = cpu;
625 schedule_work(&c_idle.work);
626 wait_for_completion(&c_idle.done);
627 if (IS_ERR(c_idle.idle))
628 return PTR_ERR(c_idle.idle);
629 idle = c_idle.idle;
630 current_set[cpu] = c_idle.idle;
631 }
Heiko Carstensda7f51c2011-01-05 12:48:09 +0100632 init_idle(idle, cpu);
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100633 if (smp_alloc_lowcore(cpu))
634 return -ENOMEM;
Heiko Carstensd0d3cdf2009-03-26 15:24:53 +0100635 do {
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100636 ccode = sigp(cpu, sigp_initial_cpu_reset);
Heiko Carstensd0d3cdf2009-03-26 15:24:53 +0100637 if (ccode == sigp_busy)
638 udelay(10);
639 if (ccode == sigp_not_operational)
640 goto err_out;
641 } while (ccode == sigp_busy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Heiko Carstensd0d3cdf2009-03-26 15:24:53 +0100643 lowcore = (u32)(unsigned long)lowcore_ptr[cpu];
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100644 while (sigp_p(lowcore, cpu, sigp_set_prefix) == sigp_busy)
Heiko Carstensd0d3cdf2009-03-26 15:24:53 +0100645 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Heiko Carstens39ce0102007-04-27 16:02:00 +0200647 cpu_lowcore = lowcore_ptr[cpu];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 cpu_lowcore->kernel_stack = (unsigned long)
Heiko Carstens39ce0102007-04-27 16:02:00 +0200649 task_stack_page(idle) + THREAD_SIZE;
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100650 cpu_lowcore->thread_info = (unsigned long) task_thread_info(idle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 sf = (struct stack_frame *) (cpu_lowcore->kernel_stack
652 - sizeof(struct pt_regs)
653 - sizeof(struct stack_frame));
654 memset(sf, 0, sizeof(struct stack_frame));
655 sf->gprs[9] = (unsigned long) sf;
656 cpu_lowcore->save_area[15] = (unsigned long) sf;
Segher Boessenkool24d3e212008-06-10 10:03:23 +0200657 __ctl_store(cpu_lowcore->cregs_save_area, 0, 15);
Martin Schwidefsky050eef32010-08-24 09:26:21 +0200658 atomic_inc(&init_mm.context.attach_count);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200659 asm volatile(
660 " stam 0,15,0(%0)"
661 : : "a" (&cpu_lowcore->access_regs_save_area) : "memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 cpu_lowcore->percpu_offset = __per_cpu_offset[cpu];
Heiko Carstens39ce0102007-04-27 16:02:00 +0200663 cpu_lowcore->current_task = (unsigned long) idle;
Martin Schwidefsky7b468482009-03-26 15:24:42 +0100664 cpu_lowcore->cpu_nr = cpu;
Heiko Carstens591bb4f2008-02-19 15:29:29 +0100665 cpu_lowcore->kernel_asce = S390_lowcore.kernel_asce;
Christian Ehrhardt25097bf2009-04-14 15:36:16 +0200666 cpu_lowcore->machine_flags = S390_lowcore.machine_flags;
Heiko Carstensdfd9f7a2009-06-12 10:26:44 +0200667 cpu_lowcore->ftrace_func = S390_lowcore.ftrace_func;
Martin Schwidefsky14375bc2010-10-25 16:10:51 +0200668 memcpy(cpu_lowcore->stfle_fac_list, S390_lowcore.stfle_fac_list,
669 MAX_FACILITY_BIT/8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 eieio();
Michael Ryan699ff132006-03-24 03:15:17 -0800671
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100672 while (sigp(cpu, sigp_restart) == sigp_busy)
Michael Ryan699ff132006-03-24 03:15:17 -0800673 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675 while (!cpu_online(cpu))
676 cpu_relax();
677 return 0;
Heiko Carstensd0d3cdf2009-03-26 15:24:53 +0100678
679err_out:
680 smp_free_lowcore(cpu);
681 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682}
683
Heiko Carstens37a33022006-02-17 13:52:47 -0800684static int __init setup_possible_cpus(char *s)
685{
Heiko Carstens48483b32008-01-26 14:11:05 +0100686 int pcpus, cpu;
687
688 pcpus = simple_strtoul(s, NULL, 0);
Heiko Carstens88e01282009-04-14 15:36:25 +0200689 init_cpu_possible(cpumask_of(0));
690 for (cpu = 1; cpu < pcpus && cpu < nr_cpu_ids; cpu++)
Rusty Russelldef6cfb2009-03-26 15:25:00 +0100691 set_cpu_possible(cpu, true);
Heiko Carstens37a33022006-02-17 13:52:47 -0800692 return 0;
693}
694early_param("possible_cpus", setup_possible_cpus);
695
Heiko Carstens48483b32008-01-26 14:11:05 +0100696#ifdef CONFIG_HOTPLUG_CPU
697
Heiko Carstens39ce0102007-04-27 16:02:00 +0200698int __cpu_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200700 struct ec_creg_mask_parms cr_parms;
Zwane Mwaikambof3705132005-06-25 14:54:50 -0700701 int cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +0200703 set_cpu_online(cpu, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 /* Disable pfault pseudo page faults on this cpu. */
Heiko Carstens29b08d22006-12-04 15:40:40 +0100706 pfault_fini();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200708 memset(&cr_parms.orvals, 0, sizeof(cr_parms.orvals));
709 memset(&cr_parms.andvals, 0xff, sizeof(cr_parms.andvals));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200711 /* disable all external interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 cr_parms.orvals[0] = 0;
Heiko Carstens5bd41872011-05-23 10:24:50 +0200713 cr_parms.andvals[0] = ~(1 << 15 | 1 << 14 | 1 << 13 | 1 << 11 |
Jan Glaubercadfce72011-07-24 10:48:30 +0200714 1 << 10 | 1 << 9 | 1 << 6 | 1 << 5 |
715 1 << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 /* disable all I/O interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 cr_parms.orvals[6] = 0;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200718 cr_parms.andvals[6] = ~(1 << 31 | 1 << 30 | 1 << 29 | 1 << 28 |
719 1 << 27 | 1 << 26 | 1 << 25 | 1 << 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 /* disable most machine checks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 cr_parms.orvals[14] = 0;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200722 cr_parms.andvals[14] = ~(1 << 28 | 1 << 27 | 1 << 26 |
723 1 << 25 | 1 << 24);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200724
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 smp_ctl_bit_callback(&cr_parms);
726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 return 0;
728}
729
Heiko Carstens39ce0102007-04-27 16:02:00 +0200730void __cpu_die(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
732 /* Wait until target cpu is down */
Heiko Carstens5c0b9122009-09-11 10:29:05 +0200733 while (!cpu_stopped(cpu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 cpu_relax();
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100735 while (sigp_p(0, cpu, sigp_set_prefix) == sigp_busy)
Heiko Carstens4f8048e2009-10-29 15:04:09 +0100736 udelay(10);
Heiko Carstens1cb6bb42008-01-26 14:11:14 +0100737 smp_free_lowcore(cpu);
Martin Schwidefsky050eef32010-08-24 09:26:21 +0200738 atomic_dec(&init_mm.context.attach_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739}
740
Heiko Carstensb456d942011-05-23 10:24:33 +0200741void __noreturn cpu_die(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
743 idle_task_exit();
Heiko Carstensa93b8ec2010-02-26 22:37:35 +0100744 while (sigp(smp_processor_id(), sigp_stop) == sigp_busy)
Heiko Carstensf8501ba2009-10-29 15:04:13 +0100745 cpu_relax();
Heiko Carstens39ce0102007-04-27 16:02:00 +0200746 for (;;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747}
748
Heiko Carstens255acee2006-02-17 13:52:46 -0800749#endif /* CONFIG_HOTPLUG_CPU */
750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751void __init smp_prepare_cpus(unsigned int max_cpus)
752{
Heiko Carstens591bb4f2008-02-19 15:29:29 +0100753#ifndef CONFIG_64BIT
754 unsigned long save_area = 0;
755#endif
756 unsigned long async_stack, panic_stack;
757 struct _lowcore *lowcore;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Heiko Carstens48483b32008-01-26 14:11:05 +0100759 smp_detect_cpus();
760
Heiko Carstens39ce0102007-04-27 16:02:00 +0200761 /* request the 0x1201 emergency signal external interrupt */
762 if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0)
763 panic("Couldn't request external interrupt 0x1201");
Martin Schwidefskyd98e19c2011-10-30 15:16:58 +0100764 /* request the 0x1202 external call external interrupt */
765 if (register_external_interrupt(0x1202, do_ext_call_interrupt) != 0)
766 panic("Couldn't request external interrupt 0x1202");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Heiko Carstens591bb4f2008-02-19 15:29:29 +0100768 /* Reallocate current lowcore, but keep its contents. */
Heiko Carstens3fd26a72009-09-22 22:58:49 +0200769 lowcore = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER);
Heiko Carstens591bb4f2008-02-19 15:29:29 +0100770 panic_stack = __get_free_page(GFP_KERNEL);
771 async_stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
Martin Schwidefskyc742b312008-12-31 15:11:42 +0100772 BUG_ON(!lowcore || !panic_stack || !async_stack);
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800773#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700774 if (MACHINE_HAS_IEEE)
Heiko Carstens591bb4f2008-02-19 15:29:29 +0100775 save_area = get_zeroed_page(GFP_KERNEL);
Heiko Carstens77fa2242005-06-25 14:55:30 -0700776#endif
Heiko Carstens591bb4f2008-02-19 15:29:29 +0100777 local_irq_disable();
778 local_mcck_disable();
779 lowcore_ptr[smp_processor_id()] = lowcore;
780 *lowcore = S390_lowcore;
781 lowcore->panic_stack = panic_stack + PAGE_SIZE;
782 lowcore->async_stack = async_stack + ASYNC_SIZE;
783#ifndef CONFIG_64BIT
784 if (MACHINE_HAS_IEEE)
785 lowcore->extended_save_area_addr = (u32) save_area;
786#endif
787 set_prefix((u32)(unsigned long) lowcore);
788 local_mcck_enable();
789 local_irq_enable();
Heiko Carstens3a6ba462009-07-24 12:39:51 +0200790#ifdef CONFIG_64BIT
791 if (vdso_alloc_per_cpu(smp_processor_id(), &S390_lowcore))
792 BUG();
793#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794}
795
Heiko Carstensea1f4ee2007-05-31 17:38:05 +0200796void __init smp_prepare_boot_cpu(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
798 BUG_ON(smp_processor_id() != 0);
799
Heiko Carstens48483b32008-01-26 14:11:05 +0100800 current_thread_info()->cpu = 0;
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +0200801 set_cpu_present(0, true);
802 set_cpu_online(0, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 S390_lowcore.percpu_offset = __per_cpu_offset[0];
804 current_set[0] = current;
Heiko Carstens08d07962008-01-26 14:10:56 +0100805 smp_cpu_state[0] = CPU_STATE_CONFIGURED;
Heiko Carstensc10fde02008-04-17 07:46:13 +0200806 smp_cpu_polarization[0] = POLARIZATION_UNKNWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807}
808
Heiko Carstensea1f4ee2007-05-31 17:38:05 +0200809void __init smp_cpus_done(unsigned int max_cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811}
812
Heiko Carstens02beacc2010-01-13 20:44:34 +0100813void __init smp_setup_processor_id(void)
814{
815 S390_lowcore.cpu_nr = 0;
816 __cpu_logical_map[0] = stap();
817}
818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819/*
820 * the frequency of the profiling timer can be changed
821 * by writing a multiplier value into /proc/profile.
822 *
823 * usually you want to run this on all CPUs ;)
824 */
825int setup_profiling_timer(unsigned int multiplier)
826{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200827 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828}
829
Heiko Carstens08d07962008-01-26 14:10:56 +0100830#ifdef CONFIG_HOTPLUG_CPU
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200831static ssize_t cpu_configure_show(struct sys_device *dev,
832 struct sysdev_attribute *attr, char *buf)
Heiko Carstens08d07962008-01-26 14:10:56 +0100833{
834 ssize_t count;
835
836 mutex_lock(&smp_cpu_state_mutex);
837 count = sprintf(buf, "%d\n", smp_cpu_state[dev->id]);
838 mutex_unlock(&smp_cpu_state_mutex);
839 return count;
840}
841
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200842static ssize_t cpu_configure_store(struct sys_device *dev,
843 struct sysdev_attribute *attr,
844 const char *buf, size_t count)
Heiko Carstens08d07962008-01-26 14:10:56 +0100845{
846 int cpu = dev->id;
847 int val, rc;
848 char delim;
849
850 if (sscanf(buf, "%d %c", &val, &delim) != 1)
851 return -EINVAL;
852 if (val != 0 && val != 1)
853 return -EINVAL;
854
Martin Schwidefsky9d40d2e2008-01-26 14:11:31 +0100855 get_online_cpus();
Heiko Carstens0b18d312008-04-30 13:38:36 +0200856 mutex_lock(&smp_cpu_state_mutex);
Heiko Carstens08d07962008-01-26 14:10:56 +0100857 rc = -EBUSY;
Heiko Carstens2c2df112010-02-26 22:37:34 +0100858 /* disallow configuration changes of online cpus and cpu 0 */
859 if (cpu_online(cpu) || cpu == 0)
Heiko Carstens08d07962008-01-26 14:10:56 +0100860 goto out;
861 rc = 0;
862 switch (val) {
863 case 0:
864 if (smp_cpu_state[cpu] == CPU_STATE_CONFIGURED) {
865 rc = sclp_cpu_deconfigure(__cpu_logical_map[cpu]);
Heiko Carstensc10fde02008-04-17 07:46:13 +0200866 if (!rc) {
Heiko Carstens08d07962008-01-26 14:10:56 +0100867 smp_cpu_state[cpu] = CPU_STATE_STANDBY;
Heiko Carstensc10fde02008-04-17 07:46:13 +0200868 smp_cpu_polarization[cpu] = POLARIZATION_UNKNWN;
869 }
Heiko Carstens08d07962008-01-26 14:10:56 +0100870 }
871 break;
872 case 1:
873 if (smp_cpu_state[cpu] == CPU_STATE_STANDBY) {
874 rc = sclp_cpu_configure(__cpu_logical_map[cpu]);
Heiko Carstensc10fde02008-04-17 07:46:13 +0200875 if (!rc) {
Heiko Carstens08d07962008-01-26 14:10:56 +0100876 smp_cpu_state[cpu] = CPU_STATE_CONFIGURED;
Heiko Carstensc10fde02008-04-17 07:46:13 +0200877 smp_cpu_polarization[cpu] = POLARIZATION_UNKNWN;
878 }
Heiko Carstens08d07962008-01-26 14:10:56 +0100879 }
880 break;
881 default:
882 break;
883 }
884out:
Heiko Carstens08d07962008-01-26 14:10:56 +0100885 mutex_unlock(&smp_cpu_state_mutex);
Heiko Carstens0b18d312008-04-30 13:38:36 +0200886 put_online_cpus();
Heiko Carstens08d07962008-01-26 14:10:56 +0100887 return rc ? rc : count;
888}
889static SYSDEV_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store);
890#endif /* CONFIG_HOTPLUG_CPU */
891
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200892static ssize_t cpu_polarization_show(struct sys_device *dev,
893 struct sysdev_attribute *attr, char *buf)
Heiko Carstensc10fde02008-04-17 07:46:13 +0200894{
895 int cpu = dev->id;
896 ssize_t count;
897
898 mutex_lock(&smp_cpu_state_mutex);
899 switch (smp_cpu_polarization[cpu]) {
900 case POLARIZATION_HRZ:
901 count = sprintf(buf, "horizontal\n");
902 break;
903 case POLARIZATION_VL:
904 count = sprintf(buf, "vertical:low\n");
905 break;
906 case POLARIZATION_VM:
907 count = sprintf(buf, "vertical:medium\n");
908 break;
909 case POLARIZATION_VH:
910 count = sprintf(buf, "vertical:high\n");
911 break;
912 default:
913 count = sprintf(buf, "unknown\n");
914 break;
915 }
916 mutex_unlock(&smp_cpu_state_mutex);
917 return count;
918}
919static SYSDEV_ATTR(polarization, 0444, cpu_polarization_show, NULL);
920
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200921static ssize_t show_cpu_address(struct sys_device *dev,
922 struct sysdev_attribute *attr, char *buf)
Heiko Carstens08d07962008-01-26 14:10:56 +0100923{
924 return sprintf(buf, "%d\n", __cpu_logical_map[dev->id]);
925}
926static SYSDEV_ATTR(address, 0444, show_cpu_address, NULL);
927
928
929static struct attribute *cpu_common_attrs[] = {
930#ifdef CONFIG_HOTPLUG_CPU
931 &attr_configure.attr,
932#endif
933 &attr_address.attr,
Heiko Carstensc10fde02008-04-17 07:46:13 +0200934 &attr_polarization.attr,
Heiko Carstens08d07962008-01-26 14:10:56 +0100935 NULL,
936};
937
938static struct attribute_group cpu_common_attr_group = {
939 .attrs = cpu_common_attrs,
940};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200942static ssize_t show_capability(struct sys_device *dev,
943 struct sysdev_attribute *attr, char *buf)
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200944{
945 unsigned int capability;
946 int rc;
947
948 rc = get_cpu_capability(&capability);
949 if (rc)
950 return rc;
951 return sprintf(buf, "%u\n", capability);
952}
953static SYSDEV_ATTR(capability, 0444, show_capability, NULL);
954
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200955static ssize_t show_idle_count(struct sys_device *dev,
956 struct sysdev_attribute *attr, char *buf)
Heiko Carstensfae8b222007-10-22 12:52:39 +0200957{
958 struct s390_idle_data *idle;
959 unsigned long long idle_count;
Martin Schwidefskye98bbaa2009-06-22 12:08:20 +0200960 unsigned int sequence;
Heiko Carstensfae8b222007-10-22 12:52:39 +0200961
962 idle = &per_cpu(s390_idle, dev->id);
Martin Schwidefskye98bbaa2009-06-22 12:08:20 +0200963repeat:
964 sequence = idle->sequence;
965 smp_rmb();
966 if (sequence & 1)
967 goto repeat;
Heiko Carstensfae8b222007-10-22 12:52:39 +0200968 idle_count = idle->idle_count;
Martin Schwidefsky6f430922008-12-31 15:11:40 +0100969 if (idle->idle_enter)
970 idle_count++;
Martin Schwidefskye98bbaa2009-06-22 12:08:20 +0200971 smp_rmb();
972 if (idle->sequence != sequence)
973 goto repeat;
Heiko Carstensfae8b222007-10-22 12:52:39 +0200974 return sprintf(buf, "%llu\n", idle_count);
975}
976static SYSDEV_ATTR(idle_count, 0444, show_idle_count, NULL);
977
Andi Kleen4a0b2b42008-07-01 18:48:41 +0200978static ssize_t show_idle_time(struct sys_device *dev,
979 struct sysdev_attribute *attr, char *buf)
Heiko Carstensfae8b222007-10-22 12:52:39 +0200980{
981 struct s390_idle_data *idle;
Martin Schwidefsky6f430922008-12-31 15:11:40 +0100982 unsigned long long now, idle_time, idle_enter;
Martin Schwidefskye98bbaa2009-06-22 12:08:20 +0200983 unsigned int sequence;
Heiko Carstensfae8b222007-10-22 12:52:39 +0200984
985 idle = &per_cpu(s390_idle, dev->id);
Martin Schwidefsky6f430922008-12-31 15:11:40 +0100986 now = get_clock();
Martin Schwidefskye98bbaa2009-06-22 12:08:20 +0200987repeat:
988 sequence = idle->sequence;
989 smp_rmb();
990 if (sequence & 1)
991 goto repeat;
Martin Schwidefsky6f430922008-12-31 15:11:40 +0100992 idle_time = idle->idle_time;
993 idle_enter = idle->idle_enter;
994 if (idle_enter != 0ULL && idle_enter < now)
995 idle_time += now - idle_enter;
Martin Schwidefskye98bbaa2009-06-22 12:08:20 +0200996 smp_rmb();
997 if (idle->sequence != sequence)
998 goto repeat;
Martin Schwidefsky6f430922008-12-31 15:11:40 +0100999 return sprintf(buf, "%llu\n", idle_time >> 12);
Heiko Carstensfae8b222007-10-22 12:52:39 +02001000}
Heiko Carstens69d39d62007-11-05 11:10:13 +01001001static SYSDEV_ATTR(idle_time_us, 0444, show_idle_time, NULL);
Heiko Carstensfae8b222007-10-22 12:52:39 +02001002
Heiko Carstens08d07962008-01-26 14:10:56 +01001003static struct attribute *cpu_online_attrs[] = {
Heiko Carstensfae8b222007-10-22 12:52:39 +02001004 &attr_capability.attr,
1005 &attr_idle_count.attr,
Heiko Carstens69d39d62007-11-05 11:10:13 +01001006 &attr_idle_time_us.attr,
Heiko Carstensfae8b222007-10-22 12:52:39 +02001007 NULL,
1008};
1009
Heiko Carstens08d07962008-01-26 14:10:56 +01001010static struct attribute_group cpu_online_attr_group = {
1011 .attrs = cpu_online_attrs,
Heiko Carstensfae8b222007-10-22 12:52:39 +02001012};
1013
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02001014static int __cpuinit smp_cpu_notify(struct notifier_block *self,
1015 unsigned long action, void *hcpu)
1016{
1017 unsigned int cpu = (unsigned int)(long)hcpu;
1018 struct cpu *c = &per_cpu(cpu_devices, cpu);
1019 struct sys_device *s = &c->sysdev;
Heiko Carstensfae8b222007-10-22 12:52:39 +02001020 struct s390_idle_data *idle;
Akinobu Mitad882ba62010-05-26 14:43:34 -07001021 int err = 0;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02001022
1023 switch (action) {
1024 case CPU_ONLINE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -07001025 case CPU_ONLINE_FROZEN:
Heiko Carstensfae8b222007-10-22 12:52:39 +02001026 idle = &per_cpu(s390_idle, cpu);
Martin Schwidefskye98bbaa2009-06-22 12:08:20 +02001027 memset(idle, 0, sizeof(struct s390_idle_data));
Akinobu Mitad882ba62010-05-26 14:43:34 -07001028 err = sysfs_create_group(&s->kobj, &cpu_online_attr_group);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02001029 break;
1030 case CPU_DEAD:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -07001031 case CPU_DEAD_FROZEN:
Heiko Carstens08d07962008-01-26 14:10:56 +01001032 sysfs_remove_group(&s->kobj, &cpu_online_attr_group);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02001033 break;
1034 }
Akinobu Mitad882ba62010-05-26 14:43:34 -07001035 return notifier_from_errno(err);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02001036}
1037
1038static struct notifier_block __cpuinitdata smp_cpu_nb = {
Heiko Carstens39ce0102007-04-27 16:02:00 +02001039 .notifier_call = smp_cpu_notify,
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02001040};
1041
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001042static int __devinit smp_add_present_cpu(int cpu)
Heiko Carstens08d07962008-01-26 14:10:56 +01001043{
1044 struct cpu *c = &per_cpu(cpu_devices, cpu);
1045 struct sys_device *s = &c->sysdev;
1046 int rc;
1047
1048 c->hotpluggable = 1;
1049 rc = register_cpu(c, cpu);
1050 if (rc)
1051 goto out;
1052 rc = sysfs_create_group(&s->kobj, &cpu_common_attr_group);
1053 if (rc)
1054 goto out_cpu;
1055 if (!cpu_online(cpu))
1056 goto out;
1057 rc = sysfs_create_group(&s->kobj, &cpu_online_attr_group);
1058 if (!rc)
1059 return 0;
1060 sysfs_remove_group(&s->kobj, &cpu_common_attr_group);
1061out_cpu:
1062#ifdef CONFIG_HOTPLUG_CPU
1063 unregister_cpu(c);
1064#endif
1065out:
1066 return rc;
1067}
1068
1069#ifdef CONFIG_HOTPLUG_CPU
Heiko Carstens1e489512008-04-30 13:38:37 +02001070
Heiko Carstens67060d92008-05-30 10:03:27 +02001071int __ref smp_rescan_cpus(void)
Heiko Carstens08d07962008-01-26 14:10:56 +01001072{
1073 cpumask_t newcpus;
1074 int cpu;
1075 int rc;
1076
Martin Schwidefsky9d40d2e2008-01-26 14:11:31 +01001077 get_online_cpus();
Heiko Carstens0b18d312008-04-30 13:38:36 +02001078 mutex_lock(&smp_cpu_state_mutex);
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +02001079 cpumask_copy(&newcpus, cpu_present_mask);
Heiko Carstens1e489512008-04-30 13:38:37 +02001080 rc = __smp_rescan_cpus();
Heiko Carstens08d07962008-01-26 14:10:56 +01001081 if (rc)
1082 goto out;
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +02001083 cpumask_andnot(&newcpus, cpu_present_mask, &newcpus);
1084 for_each_cpu(cpu, &newcpus) {
Heiko Carstens08d07962008-01-26 14:10:56 +01001085 rc = smp_add_present_cpu(cpu);
1086 if (rc)
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +02001087 set_cpu_present(cpu, false);
Heiko Carstens08d07962008-01-26 14:10:56 +01001088 }
1089 rc = 0;
1090out:
Heiko Carstens08d07962008-01-26 14:10:56 +01001091 mutex_unlock(&smp_cpu_state_mutex);
Heiko Carstens0b18d312008-04-30 13:38:36 +02001092 put_online_cpus();
KOSAKI Motohiro0f1959f2011-05-23 10:24:36 +02001093 if (!cpumask_empty(&newcpus))
Heiko Carstensc10fde02008-04-17 07:46:13 +02001094 topology_schedule_update();
Heiko Carstens1e489512008-04-30 13:38:37 +02001095 return rc;
1096}
1097
Andi Kleenc9be0a32010-01-05 12:47:58 +01001098static ssize_t __ref rescan_store(struct sysdev_class *class,
1099 struct sysdev_class_attribute *attr,
1100 const char *buf,
Heiko Carstens1e489512008-04-30 13:38:37 +02001101 size_t count)
1102{
1103 int rc;
1104
1105 rc = smp_rescan_cpus();
Heiko Carstens08d07962008-01-26 14:10:56 +01001106 return rc ? rc : count;
1107}
Heiko Carstensda5aae72008-10-28 11:10:16 +01001108static SYSDEV_CLASS_ATTR(rescan, 0200, NULL, rescan_store);
Heiko Carstens08d07962008-01-26 14:10:56 +01001109#endif /* CONFIG_HOTPLUG_CPU */
1110
Heiko Carstens5fbcae52010-02-12 11:19:24 +01001111static ssize_t dispatching_show(struct sysdev_class *class,
1112 struct sysdev_class_attribute *attr,
1113 char *buf)
Heiko Carstensc10fde02008-04-17 07:46:13 +02001114{
1115 ssize_t count;
1116
1117 mutex_lock(&smp_cpu_state_mutex);
1118 count = sprintf(buf, "%d\n", cpu_management);
1119 mutex_unlock(&smp_cpu_state_mutex);
1120 return count;
1121}
1122
Andi Kleenc9be0a32010-01-05 12:47:58 +01001123static ssize_t dispatching_store(struct sysdev_class *dev,
1124 struct sysdev_class_attribute *attr,
1125 const char *buf,
Heiko Carstensda5aae72008-10-28 11:10:16 +01001126 size_t count)
Heiko Carstensc10fde02008-04-17 07:46:13 +02001127{
1128 int val, rc;
1129 char delim;
1130
1131 if (sscanf(buf, "%d %c", &val, &delim) != 1)
1132 return -EINVAL;
1133 if (val != 0 && val != 1)
1134 return -EINVAL;
1135 rc = 0;
Heiko Carstensc10fde02008-04-17 07:46:13 +02001136 get_online_cpus();
Heiko Carstens0b18d312008-04-30 13:38:36 +02001137 mutex_lock(&smp_cpu_state_mutex);
Heiko Carstensc10fde02008-04-17 07:46:13 +02001138 if (cpu_management == val)
1139 goto out;
1140 rc = topology_set_cpu_management(val);
1141 if (!rc)
1142 cpu_management = val;
1143out:
Heiko Carstensc10fde02008-04-17 07:46:13 +02001144 mutex_unlock(&smp_cpu_state_mutex);
Heiko Carstens0b18d312008-04-30 13:38:36 +02001145 put_online_cpus();
Heiko Carstensc10fde02008-04-17 07:46:13 +02001146 return rc ? rc : count;
1147}
Heiko Carstensda5aae72008-10-28 11:10:16 +01001148static SYSDEV_CLASS_ATTR(dispatching, 0644, dispatching_show,
1149 dispatching_store);
Heiko Carstensc10fde02008-04-17 07:46:13 +02001150
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151static int __init topology_init(void)
1152{
1153 int cpu;
Heiko Carstensfae8b222007-10-22 12:52:39 +02001154 int rc;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +02001155
1156 register_cpu_notifier(&smp_cpu_nb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Heiko Carstens08d07962008-01-26 14:10:56 +01001158#ifdef CONFIG_HOTPLUG_CPU
Heiko Carstensda5aae72008-10-28 11:10:16 +01001159 rc = sysdev_class_create_file(&cpu_sysdev_class, &attr_rescan);
Heiko Carstens08d07962008-01-26 14:10:56 +01001160 if (rc)
1161 return rc;
1162#endif
Heiko Carstensda5aae72008-10-28 11:10:16 +01001163 rc = sysdev_class_create_file(&cpu_sysdev_class, &attr_dispatching);
Heiko Carstensc10fde02008-04-17 07:46:13 +02001164 if (rc)
1165 return rc;
Heiko Carstens08d07962008-01-26 14:10:56 +01001166 for_each_present_cpu(cpu) {
1167 rc = smp_add_present_cpu(cpu);
Heiko Carstensfae8b222007-10-22 12:52:39 +02001168 if (rc)
1169 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 }
1171 return 0;
1172}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173subsys_initcall(topology_init);