blob: b05ae8584258e3f9081da0e60f2733d8fea54436 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/kernel/smp.c
3 *
Heiko Carstens39ce0102007-04-27 16:02:00 +02004 * Copyright IBM Corp. 1999,2007
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
23#include <linux/module.h>
24#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/mm.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040026#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/spinlock.h>
28#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/delay.h>
30#include <linux/cache.h>
31#include <linux/interrupt.h>
32#include <linux/cpu.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010033#include <linux/timex.h>
Michael Holzheu411ed322007-04-27 16:01:49 +020034#include <linux/bootmem.h>
Michael Holzheu46b05d22007-02-21 10:55:21 +010035#include <asm/ipl.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010036#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/sigp.h>
38#include <asm/pgalloc.h>
39#include <asm/irq.h>
40#include <asm/s390_ext.h>
41#include <asm/cpcmd.h>
42#include <asm/tlbflush.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010043#include <asm/timer.h>
Michael Holzheu411ed322007-04-27 16:01:49 +020044#include <asm/lowcore.h>
Heiko Carstensfae8b222007-10-22 12:52:39 +020045#include <asm/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047/*
48 * An array with a pointer the lowcore of every CPU.
49 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050struct _lowcore *lowcore_ptr[NR_CPUS];
Heiko Carstens39ce0102007-04-27 16:02:00 +020051EXPORT_SYMBOL(lowcore_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Heiko Carstens255acee2006-02-17 13:52:46 -080053cpumask_t cpu_online_map = CPU_MASK_NONE;
Heiko Carstens39ce0102007-04-27 16:02:00 +020054EXPORT_SYMBOL(cpu_online_map);
55
Heiko Carstens255acee2006-02-17 13:52:46 -080056cpumask_t cpu_possible_map = CPU_MASK_NONE;
Heiko Carstens39ce0102007-04-27 16:02:00 +020057EXPORT_SYMBOL(cpu_possible_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59static struct task_struct *current_set[NR_CPUS];
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061static void smp_ext_bitcall(int, ec_bit_sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63/*
Jan Glauber63db6e82007-02-21 10:55:06 +010064 * Structure and data for __smp_call_function_map(). This is designed to
65 * minimise static memory requirements. It also looks cleaner.
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 */
67static DEFINE_SPINLOCK(call_lock);
68
69struct call_data_struct {
70 void (*func) (void *info);
71 void *info;
Jan Glauber63db6e82007-02-21 10:55:06 +010072 cpumask_t started;
73 cpumask_t finished;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 int wait;
75};
76
Heiko Carstens39ce0102007-04-27 16:02:00 +020077static struct call_data_struct *call_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79/*
80 * 'Call function' interrupt callback
81 */
82static void do_call_function(void)
83{
84 void (*func) (void *info) = call_data->func;
85 void *info = call_data->info;
86 int wait = call_data->wait;
87
Jan Glauber63db6e82007-02-21 10:55:06 +010088 cpu_set(smp_processor_id(), call_data->started);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 (*func)(info);
90 if (wait)
Jan Glauber63db6e82007-02-21 10:55:06 +010091 cpu_set(smp_processor_id(), call_data->finished);;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Jan Glauber63db6e82007-02-21 10:55:06 +010094static void __smp_call_function_map(void (*func) (void *info), void *info,
95 int nonatomic, int wait, cpumask_t map)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
97 struct call_data_struct data;
Jan Glauber63db6e82007-02-21 10:55:06 +010098 int cpu, local = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Jan Glauber63db6e82007-02-21 10:55:06 +0100100 /*
Heiko Carstens25864162007-03-05 23:35:41 +0100101 * Can deadlock when interrupts are disabled or if in wrong context.
Jan Glauber63db6e82007-02-21 10:55:06 +0100102 */
Heiko Carstens25864162007-03-05 23:35:41 +0100103 WARN_ON(irqs_disabled() || in_irq());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Jan Glauber63db6e82007-02-21 10:55:06 +0100105 /*
106 * Check for local function call. We have to have the same call order
107 * as in on_each_cpu() because of machine_restart_smp().
108 */
109 if (cpu_isset(smp_processor_id(), map)) {
110 local = 1;
111 cpu_clear(smp_processor_id(), map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
113
Jan Glauber63db6e82007-02-21 10:55:06 +0100114 cpus_and(map, map, cpu_online_map);
115 if (cpus_empty(map))
116 goto out;
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 data.func = func;
119 data.info = info;
Jan Glauber63db6e82007-02-21 10:55:06 +0100120 data.started = CPU_MASK_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 data.wait = wait;
122 if (wait)
Jan Glauber63db6e82007-02-21 10:55:06 +0100123 data.finished = CPU_MASK_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Heiko Carstens8da1aec2007-07-27 12:29:09 +0200125 spin_lock(&call_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 call_data = &data;
Jan Glauber63db6e82007-02-21 10:55:06 +0100127
128 for_each_cpu_mask(cpu, map)
129 smp_ext_bitcall(cpu, ec_call_function);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 /* Wait for response */
Jan Glauber63db6e82007-02-21 10:55:06 +0100132 while (!cpus_equal(map, data.started))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 if (wait)
Jan Glauber63db6e82007-02-21 10:55:06 +0100135 while (!cpus_equal(map, data.finished))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 cpu_relax();
Heiko Carstens8da1aec2007-07-27 12:29:09 +0200137 spin_unlock(&call_lock);
Jan Glauber63db6e82007-02-21 10:55:06 +0100138out:
Heiko Carstens8da1aec2007-07-27 12:29:09 +0200139 if (local) {
140 local_irq_disable();
Jan Glauber63db6e82007-02-21 10:55:06 +0100141 func(info);
Heiko Carstens8da1aec2007-07-27 12:29:09 +0200142 local_irq_enable();
143 }
Jan Glauber63db6e82007-02-21 10:55:06 +0100144}
145
146/*
147 * smp_call_function:
148 * @func: the function to run; this must be fast and non-blocking
149 * @info: an arbitrary pointer to pass to the function
150 * @nonatomic: unused
151 * @wait: if true, wait (atomically) until function has completed on other CPUs
152 *
153 * Run a function on all other CPUs.
154 *
Heiko Carstens39ce0102007-04-27 16:02:00 +0200155 * You must not call this function with disabled interrupts, from a
156 * hardware interrupt handler or from a bottom half.
Jan Glauber63db6e82007-02-21 10:55:06 +0100157 */
158int smp_call_function(void (*func) (void *info), void *info, int nonatomic,
159 int wait)
160{
161 cpumask_t map;
162
Heiko Carstens25864162007-03-05 23:35:41 +0100163 preempt_disable();
Jan Glauber63db6e82007-02-21 10:55:06 +0100164 map = cpu_online_map;
165 cpu_clear(smp_processor_id(), map);
166 __smp_call_function_map(func, info, nonatomic, wait, map);
Heiko Carstens25864162007-03-05 23:35:41 +0100167 preempt_enable();
Jan Glauber63db6e82007-02-21 10:55:06 +0100168 return 0;
169}
170EXPORT_SYMBOL(smp_call_function);
171
172/*
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200173 * smp_call_function_single:
174 * @cpu: the CPU where func should run
Jan Glauber63db6e82007-02-21 10:55:06 +0100175 * @func: the function to run; this must be fast and non-blocking
176 * @info: an arbitrary pointer to pass to the function
177 * @nonatomic: unused
178 * @wait: if true, wait (atomically) until function has completed on other CPUs
Jan Glauber63db6e82007-02-21 10:55:06 +0100179 *
180 * Run a function on one processor.
181 *
Heiko Carstens39ce0102007-04-27 16:02:00 +0200182 * You must not call this function with disabled interrupts, from a
183 * hardware interrupt handler or from a bottom half.
Jan Glauber63db6e82007-02-21 10:55:06 +0100184 */
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200185int smp_call_function_single(int cpu, void (*func) (void *info), void *info,
186 int nonatomic, int wait)
Jan Glauber63db6e82007-02-21 10:55:06 +0100187{
Heiko Carstens25864162007-03-05 23:35:41 +0100188 preempt_disable();
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200189 __smp_call_function_map(func, info, nonatomic, wait,
190 cpumask_of_cpu(cpu));
Heiko Carstens25864162007-03-05 23:35:41 +0100191 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return 0;
193}
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200194EXPORT_SYMBOL(smp_call_function_single);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100196static void do_send_stop(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200198 int cpu, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Heiko Carstens39ce0102007-04-27 16:02:00 +0200200 /* stop all processors */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 for_each_online_cpu(cpu) {
202 if (cpu == smp_processor_id())
203 continue;
204 do {
205 rc = signal_processor(cpu, sigp_stop);
206 } while (rc == sigp_busy);
207 }
208}
209
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100210static void do_store_status(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200212 int cpu, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Heiko Carstens39ce0102007-04-27 16:02:00 +0200214 /* store status of all processors in their lowcores (real 0) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 for_each_online_cpu(cpu) {
216 if (cpu == smp_processor_id())
217 continue;
218 do {
219 rc = signal_processor_p(
220 (__u32)(unsigned long) lowcore_ptr[cpu], cpu,
221 sigp_store_status_at_address);
Heiko Carstens39ce0102007-04-27 16:02:00 +0200222 } while (rc == sigp_busy);
223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100226static void do_wait_for_stop(void)
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100227{
228 int cpu;
229
230 /* Wait for all other cpus to enter stopped state */
231 for_each_online_cpu(cpu) {
232 if (cpu == smp_processor_id())
233 continue;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200234 while (!smp_cpu_not_running(cpu))
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100235 cpu_relax();
236 }
237}
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/*
240 * this function sends a 'stop' sigp to all other CPUs in the system.
241 * it goes straight through.
242 */
243void smp_send_stop(void)
244{
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100245 /* Disable all interrupts/machine checks */
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100246 __load_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK);
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100247
Heiko Carstens39ce0102007-04-27 16:02:00 +0200248 /* write magic number to zero page (absolute 0) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 lowcore_ptr[smp_processor_id()]->panic_magic = __PANIC_MAGIC;
250
251 /* stop other processors. */
252 do_send_stop();
253
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100254 /* wait until other processors are stopped */
255 do_wait_for_stop();
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 /* store status of other processors. */
258 do_store_status();
259}
260
261/*
262 * Reboot, halt and power_off routines for SMP.
263 */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200264void machine_restart_smp(char *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100266 smp_send_stop();
267 do_reipl();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268}
269
270void machine_halt_smp(void)
271{
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100272 smp_send_stop();
273 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
274 __cpcmd(vmhalt_cmd, NULL, 0, NULL);
275 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
276 for (;;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
279void machine_power_off_smp(void)
280{
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100281 smp_send_stop();
282 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
283 __cpcmd(vmpoff_cmd, NULL, 0, NULL);
284 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
285 for (;;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
287
288/*
289 * This is the main routine where commands issued by other
290 * cpus are handled.
291 */
292
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100293static void do_ext_call_interrupt(__u16 code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200295 unsigned long bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Heiko Carstens39ce0102007-04-27 16:02:00 +0200297 /*
298 * handle bit signal external calls
299 *
300 * For the ec_schedule signal we have to do nothing. All the work
301 * is done automatically when we return from the interrupt.
302 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 bits = xchg(&S390_lowcore.ext_call_fast, 0);
304
Heiko Carstens39ce0102007-04-27 16:02:00 +0200305 if (test_bit(ec_call_function, &bits))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 do_call_function();
307}
308
309/*
310 * Send an external call sigp to another cpu and return without waiting
311 * for its completion.
312 */
313static void smp_ext_bitcall(int cpu, ec_bit_sig sig)
314{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200315 /*
316 * Set signaling bit in lowcore of target cpu and kick it
317 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast);
Heiko Carstens39ce0102007-04-27 16:02:00 +0200319 while (signal_processor(cpu, sigp_emergency_signal) == sigp_busy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 udelay(10);
321}
322
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800323#ifndef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324/*
325 * this function sends a 'purge tlb' signal to another CPU.
326 */
327void smp_ptlb_callback(void *info)
328{
Martin Schwidefskyba8a9222007-10-22 12:52:44 +0200329 __tlb_flush_local();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330}
331
332void smp_ptlb_all(void)
333{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200334 on_each_cpu(smp_ptlb_callback, NULL, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336EXPORT_SYMBOL(smp_ptlb_all);
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800337#endif /* ! CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339/*
340 * this function sends a 'reschedule' IPI to another CPU.
341 * it goes straight through and wastes no time serializing
342 * anything. Worst case is that we lose a reschedule ...
343 */
344void smp_send_reschedule(int cpu)
345{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200346 smp_ext_bitcall(cpu, ec_schedule);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
349/*
350 * parameter area for the set/clear control bit callbacks
351 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200352struct ec_creg_mask_parms {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 unsigned long orvals[16];
354 unsigned long andvals[16];
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200355};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357/*
358 * callback for setting/clearing control bits
359 */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200360static void smp_ctl_bit_callback(void *info)
361{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200362 struct ec_creg_mask_parms *pp = info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 unsigned long cregs[16];
364 int i;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200365
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200366 __ctl_store(cregs, 0, 15);
367 for (i = 0; i <= 15; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 cregs[i] = (cregs[i] & pp->andvals[i]) | pp->orvals[i];
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200369 __ctl_load(cregs, 0, 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370}
371
372/*
373 * Set a bit in a control register of all cpus
374 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200375void smp_ctl_set_bit(int cr, int bit)
376{
377 struct ec_creg_mask_parms parms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200379 memset(&parms.orvals, 0, sizeof(parms.orvals));
380 memset(&parms.andvals, 0xff, sizeof(parms.andvals));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 parms.orvals[cr] = 1 << bit;
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200382 on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383}
Heiko Carstens39ce0102007-04-27 16:02:00 +0200384EXPORT_SYMBOL(smp_ctl_set_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386/*
387 * Clear a bit in a control register of all cpus
388 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200389void smp_ctl_clear_bit(int cr, int bit)
390{
391 struct ec_creg_mask_parms parms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200393 memset(&parms.orvals, 0, sizeof(parms.orvals));
394 memset(&parms.andvals, 0xff, sizeof(parms.andvals));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 parms.andvals[cr] = ~(1L << bit);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200396 on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
Heiko Carstens39ce0102007-04-27 16:02:00 +0200398EXPORT_SYMBOL(smp_ctl_clear_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Michael Holzheu411ed322007-04-27 16:01:49 +0200400#if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_ZFCPDUMP_MODULE)
401
402/*
403 * zfcpdump_prefix_array holds prefix registers for the following scenario:
404 * 64 bit zfcpdump kernel and 31 bit kernel which is to be dumped. We have to
405 * save its prefix registers, since they get lost, when switching from 31 bit
406 * to 64 bit.
407 */
408unsigned int zfcpdump_prefix_array[NR_CPUS + 1] \
409 __attribute__((__section__(".data")));
410
Heiko Carstens285f6722007-07-10 11:24:13 +0200411static void __init smp_get_save_area(unsigned int cpu, unsigned int phy_cpu)
Michael Holzheu411ed322007-04-27 16:01:49 +0200412{
Michael Holzheu411ed322007-04-27 16:01:49 +0200413 if (ipl_info.type != IPL_TYPE_FCP_DUMP)
414 return;
Heiko Carstens285f6722007-07-10 11:24:13 +0200415 if (cpu >= NR_CPUS) {
416 printk(KERN_WARNING "Registers for cpu %i not saved since dump "
417 "kernel was compiled with NR_CPUS=%i\n", cpu, NR_CPUS);
418 return;
Michael Holzheu411ed322007-04-27 16:01:49 +0200419 }
Heiko Carstens285f6722007-07-10 11:24:13 +0200420 zfcpdump_save_areas[cpu] = alloc_bootmem(sizeof(union save_area));
421 __cpu_logical_map[1] = (__u16) phy_cpu;
422 while (signal_processor(1, sigp_stop_and_store_status) == sigp_busy)
423 cpu_relax();
424 memcpy(zfcpdump_save_areas[cpu],
425 (void *)(unsigned long) store_prefix() + SAVE_AREA_BASE,
426 SAVE_AREA_SIZE);
427#ifdef CONFIG_64BIT
428 /* copy original prefix register */
429 zfcpdump_save_areas[cpu]->s390x.pref_reg = zfcpdump_prefix_array[cpu];
430#endif
Michael Holzheu411ed322007-04-27 16:01:49 +0200431}
432
433union save_area *zfcpdump_save_areas[NR_CPUS + 1];
434EXPORT_SYMBOL_GPL(zfcpdump_save_areas);
435
436#else
Heiko Carstens285f6722007-07-10 11:24:13 +0200437
438static inline void smp_get_save_area(unsigned int cpu, unsigned int phy_cpu) { }
439
440#endif /* CONFIG_ZFCPDUMP || CONFIG_ZFCPDUMP_MODULE */
Michael Holzheu411ed322007-04-27 16:01:49 +0200441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442/*
443 * Lets check how many CPUs we have.
444 */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200445static unsigned int __init smp_count_cpus(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
Heiko Carstens255acee2006-02-17 13:52:46 -0800447 unsigned int cpu, num_cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 __u16 boot_cpu_addr;
449
450 /*
451 * cpu 0 is the boot cpu. See smp_prepare_boot_cpu.
452 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 boot_cpu_addr = S390_lowcore.cpu_data.cpu_addr;
454 current_thread_info()->cpu = 0;
455 num_cpus = 1;
Heiko Carstens255acee2006-02-17 13:52:46 -0800456 for (cpu = 0; cpu <= 65535; cpu++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 if ((__u16) cpu == boot_cpu_addr)
458 continue;
Heiko Carstens255acee2006-02-17 13:52:46 -0800459 __cpu_logical_map[1] = (__u16) cpu;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200460 if (signal_processor(1, sigp_sense) == sigp_not_operational)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 continue;
Heiko Carstens285f6722007-07-10 11:24:13 +0200462 smp_get_save_area(num_cpus, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 num_cpus++;
464 }
Heiko Carstens39ce0102007-04-27 16:02:00 +0200465 printk("Detected %d CPU's\n", (int) num_cpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 printk("Boot cpu address %2X\n", boot_cpu_addr);
Heiko Carstens255acee2006-02-17 13:52:46 -0800467 return num_cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
470/*
Heiko Carstens39ce0102007-04-27 16:02:00 +0200471 * Activate a secondary processor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 */
Heiko Carstensea1f4ee2007-05-31 17:38:05 +0200473int __cpuinit start_secondary(void *cpuvoid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200475 /* Setup the cpu */
476 cpu_init();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800477 preempt_disable();
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100478 /* Enable TOD clock interrupts on the secondary cpu. */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200479 init_cpu_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#ifdef CONFIG_VIRT_TIMER
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100481 /* Enable cpu timer interrupts on the secondary cpu. */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200482 init_cpu_vtimer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 /* Enable pfault pseudo page faults on this cpu. */
Heiko Carstens29b08d22006-12-04 15:40:40 +0100485 pfault_init();
486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 /* Mark this cpu as online */
488 cpu_set(smp_processor_id(), cpu_online_map);
489 /* Switch on interrupts */
490 local_irq_enable();
Heiko Carstens39ce0102007-04-27 16:02:00 +0200491 /* Print info about this processor */
492 print_cpu_info(&S390_lowcore.cpu_data);
493 /* cpu_idle will call schedule for us */
494 cpu_idle();
495 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496}
497
Heiko Carstensfae8b222007-10-22 12:52:39 +0200498DEFINE_PER_CPU(struct s390_idle_data, s390_idle);
499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500static void __init smp_create_idle(unsigned int cpu)
501{
502 struct task_struct *p;
503
504 /*
505 * don't care about the psw and regs settings since we'll never
506 * reschedule the forked task.
507 */
508 p = fork_idle(cpu);
509 if (IS_ERR(p))
510 panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
511 current_set[cpu] = p;
Heiko Carstensfae8b222007-10-22 12:52:39 +0200512 spin_lock_init(&(&per_cpu(s390_idle, cpu))->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
Heiko Carstens39ce0102007-04-27 16:02:00 +0200515static int cpu_stopped(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
517 __u32 status;
518
519 /* Check for stopped state */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200520 if (signal_processor_ps(&status, 0, cpu, sigp_sense) ==
521 sigp_status_stored) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (status & 0x40)
523 return 1;
524 }
525 return 0;
526}
527
528/* Upping and downing of CPUs */
529
Heiko Carstens39ce0102007-04-27 16:02:00 +0200530int __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
532 struct task_struct *idle;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200533 struct _lowcore *cpu_lowcore;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 struct stack_frame *sf;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200535 sigp_ccode ccode;
536 int curr_cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 for (curr_cpu = 0; curr_cpu <= 65535; curr_cpu++) {
539 __cpu_logical_map[cpu] = (__u16) curr_cpu;
540 if (cpu_stopped(cpu))
541 break;
542 }
543
544 if (!cpu_stopped(cpu))
545 return -ENODEV;
546
547 ccode = signal_processor_p((__u32)(unsigned long)(lowcore_ptr[cpu]),
548 cpu, sigp_set_prefix);
Heiko Carstens39ce0102007-04-27 16:02:00 +0200549 if (ccode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 printk("sigp_set_prefix failed for cpu %d "
551 "with condition code %d\n",
552 (int) cpu, (int) ccode);
553 return -EIO;
554 }
555
556 idle = current_set[cpu];
Heiko Carstens39ce0102007-04-27 16:02:00 +0200557 cpu_lowcore = lowcore_ptr[cpu];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 cpu_lowcore->kernel_stack = (unsigned long)
Heiko Carstens39ce0102007-04-27 16:02:00 +0200559 task_stack_page(idle) + THREAD_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 sf = (struct stack_frame *) (cpu_lowcore->kernel_stack
561 - sizeof(struct pt_regs)
562 - sizeof(struct stack_frame));
563 memset(sf, 0, sizeof(struct stack_frame));
564 sf->gprs[9] = (unsigned long) sf;
565 cpu_lowcore->save_area[15] = (unsigned long) sf;
566 __ctl_store(cpu_lowcore->cregs_save_area[0], 0, 15);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200567 asm volatile(
568 " stam 0,15,0(%0)"
569 : : "a" (&cpu_lowcore->access_regs_save_area) : "memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 cpu_lowcore->percpu_offset = __per_cpu_offset[cpu];
Heiko Carstens39ce0102007-04-27 16:02:00 +0200571 cpu_lowcore->current_task = (unsigned long) idle;
572 cpu_lowcore->cpu_data.cpu_nr = cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 eieio();
Michael Ryan699ff132006-03-24 03:15:17 -0800574
Heiko Carstens39ce0102007-04-27 16:02:00 +0200575 while (signal_processor(cpu, sigp_restart) == sigp_busy)
Michael Ryan699ff132006-03-24 03:15:17 -0800576 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 while (!cpu_online(cpu))
579 cpu_relax();
580 return 0;
581}
582
Heiko Carstens255acee2006-02-17 13:52:46 -0800583static unsigned int __initdata additional_cpus;
Heiko Carstens37a33022006-02-17 13:52:47 -0800584static unsigned int __initdata possible_cpus;
Heiko Carstens255acee2006-02-17 13:52:46 -0800585
586void __init smp_setup_cpu_possible_map(void)
587{
Heiko Carstens54330452006-02-17 13:52:48 -0800588 unsigned int phy_cpus, pos_cpus, cpu;
Heiko Carstens255acee2006-02-17 13:52:46 -0800589
Heiko Carstens54330452006-02-17 13:52:48 -0800590 phy_cpus = smp_count_cpus();
591 pos_cpus = min(phy_cpus + additional_cpus, (unsigned int) NR_CPUS);
Heiko Carstens255acee2006-02-17 13:52:46 -0800592
Heiko Carstens37a33022006-02-17 13:52:47 -0800593 if (possible_cpus)
Heiko Carstens54330452006-02-17 13:52:48 -0800594 pos_cpus = min(possible_cpus, (unsigned int) NR_CPUS);
Heiko Carstens255acee2006-02-17 13:52:46 -0800595
Heiko Carstens54330452006-02-17 13:52:48 -0800596 for (cpu = 0; cpu < pos_cpus; cpu++)
Heiko Carstens255acee2006-02-17 13:52:46 -0800597 cpu_set(cpu, cpu_possible_map);
598
Heiko Carstens54330452006-02-17 13:52:48 -0800599 phy_cpus = min(phy_cpus, pos_cpus);
600
601 for (cpu = 0; cpu < phy_cpus; cpu++)
602 cpu_set(cpu, cpu_present_map);
Heiko Carstens255acee2006-02-17 13:52:46 -0800603}
604
605#ifdef CONFIG_HOTPLUG_CPU
606
607static int __init setup_additional_cpus(char *s)
608{
609 additional_cpus = simple_strtoul(s, NULL, 0);
610 return 0;
611}
612early_param("additional_cpus", setup_additional_cpus);
613
Heiko Carstens37a33022006-02-17 13:52:47 -0800614static int __init setup_possible_cpus(char *s)
615{
616 possible_cpus = simple_strtoul(s, NULL, 0);
617 return 0;
618}
619early_param("possible_cpus", setup_possible_cpus);
620
Heiko Carstens39ce0102007-04-27 16:02:00 +0200621int __cpu_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200623 struct ec_creg_mask_parms cr_parms;
Zwane Mwaikambof3705132005-06-25 14:54:50 -0700624 int cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Zwane Mwaikambof3705132005-06-25 14:54:50 -0700626 cpu_clear(cpu, cpu_online_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 /* Disable pfault pseudo page faults on this cpu. */
Heiko Carstens29b08d22006-12-04 15:40:40 +0100629 pfault_fini();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200631 memset(&cr_parms.orvals, 0, sizeof(cr_parms.orvals));
632 memset(&cr_parms.andvals, 0xff, sizeof(cr_parms.andvals));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200634 /* disable all external interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 cr_parms.orvals[0] = 0;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200636 cr_parms.andvals[0] = ~(1 << 15 | 1 << 14 | 1 << 13 | 1 << 12 |
637 1 << 11 | 1 << 10 | 1 << 6 | 1 << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 /* disable all I/O interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 cr_parms.orvals[6] = 0;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200640 cr_parms.andvals[6] = ~(1 << 31 | 1 << 30 | 1 << 29 | 1 << 28 |
641 1 << 27 | 1 << 26 | 1 << 25 | 1 << 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 /* disable most machine checks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 cr_parms.orvals[14] = 0;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200644 cr_parms.andvals[14] = ~(1 << 28 | 1 << 27 | 1 << 26 |
645 1 << 25 | 1 << 24);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 smp_ctl_bit_callback(&cr_parms);
648
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 return 0;
650}
651
Heiko Carstens39ce0102007-04-27 16:02:00 +0200652void __cpu_die(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
654 /* Wait until target cpu is down */
655 while (!smp_cpu_not_running(cpu))
656 cpu_relax();
657 printk("Processor %d spun down\n", cpu);
658}
659
Heiko Carstens39ce0102007-04-27 16:02:00 +0200660void cpu_die(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661{
662 idle_task_exit();
663 signal_processor(smp_processor_id(), sigp_stop);
664 BUG();
Heiko Carstens39ce0102007-04-27 16:02:00 +0200665 for (;;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
Heiko Carstens255acee2006-02-17 13:52:46 -0800668#endif /* CONFIG_HOTPLUG_CPU */
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670/*
671 * Cycle through the processors and setup structures.
672 */
673
674void __init smp_prepare_cpus(unsigned int max_cpus)
675{
676 unsigned long stack;
677 unsigned int cpu;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200678 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Heiko Carstens39ce0102007-04-27 16:02:00 +0200680 /* request the 0x1201 emergency signal external interrupt */
681 if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0)
682 panic("Couldn't request external interrupt 0x1201");
683 memset(lowcore_ptr, 0, sizeof(lowcore_ptr));
684 /*
685 * Initialize prefix pages and stacks for all possible cpus
686 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 print_cpu_info(&S390_lowcore.cpu_data);
688
Heiko Carstens39ce0102007-04-27 16:02:00 +0200689 for_each_possible_cpu(i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 lowcore_ptr[i] = (struct _lowcore *)
Heiko Carstens39ce0102007-04-27 16:02:00 +0200691 __get_free_pages(GFP_KERNEL | GFP_DMA,
692 sizeof(void*) == 8 ? 1 : 0);
693 stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
694 if (!lowcore_ptr[i] || !stack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 panic("smp_boot_cpus failed to allocate memory\n");
696
697 *(lowcore_ptr[i]) = S390_lowcore;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200698 lowcore_ptr[i]->async_stack = stack + ASYNC_SIZE;
699 stack = __get_free_pages(GFP_KERNEL, 0);
700 if (!stack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 panic("smp_boot_cpus failed to allocate memory\n");
Heiko Carstens39ce0102007-04-27 16:02:00 +0200702 lowcore_ptr[i]->panic_stack = stack + PAGE_SIZE;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800703#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700704 if (MACHINE_HAS_IEEE) {
705 lowcore_ptr[i]->extended_save_area_addr =
Heiko Carstens39ce0102007-04-27 16:02:00 +0200706 (__u32) __get_free_pages(GFP_KERNEL, 0);
707 if (!lowcore_ptr[i]->extended_save_area_addr)
Heiko Carstens77fa2242005-06-25 14:55:30 -0700708 panic("smp_boot_cpus failed to "
709 "allocate memory\n");
710 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711#endif
712 }
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800713#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700714 if (MACHINE_HAS_IEEE)
715 ctl_set_bit(14, 29); /* enable extended save area */
716#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 set_prefix((u32)(unsigned long) lowcore_ptr[smp_processor_id()]);
718
KAMEZAWA Hiroyuki97db7fb2006-03-31 02:30:26 -0800719 for_each_possible_cpu(cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if (cpu != smp_processor_id())
721 smp_create_idle(cpu);
722}
723
Heiko Carstensea1f4ee2007-05-31 17:38:05 +0200724void __init smp_prepare_boot_cpu(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
726 BUG_ON(smp_processor_id() != 0);
727
728 cpu_set(0, cpu_online_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 S390_lowcore.percpu_offset = __per_cpu_offset[0];
730 current_set[0] = current;
Heiko Carstensfae8b222007-10-22 12:52:39 +0200731 spin_lock_init(&(&__get_cpu_var(s390_idle))->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732}
733
Heiko Carstensea1f4ee2007-05-31 17:38:05 +0200734void __init smp_cpus_done(unsigned int max_cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Heiko Carstens54330452006-02-17 13:52:48 -0800736 cpu_present_map = cpu_possible_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737}
738
739/*
740 * the frequency of the profiling timer can be changed
741 * by writing a multiplier value into /proc/profile.
742 *
743 * usually you want to run this on all CPUs ;)
744 */
745int setup_profiling_timer(unsigned int multiplier)
746{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200747 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748}
749
750static DEFINE_PER_CPU(struct cpu, cpu_devices);
751
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200752static ssize_t show_capability(struct sys_device *dev, char *buf)
753{
754 unsigned int capability;
755 int rc;
756
757 rc = get_cpu_capability(&capability);
758 if (rc)
759 return rc;
760 return sprintf(buf, "%u\n", capability);
761}
762static SYSDEV_ATTR(capability, 0444, show_capability, NULL);
763
Heiko Carstensfae8b222007-10-22 12:52:39 +0200764static ssize_t show_idle_count(struct sys_device *dev, char *buf)
765{
766 struct s390_idle_data *idle;
767 unsigned long long idle_count;
768
769 idle = &per_cpu(s390_idle, dev->id);
770 spin_lock_irq(&idle->lock);
771 idle_count = idle->idle_count;
772 spin_unlock_irq(&idle->lock);
773 return sprintf(buf, "%llu\n", idle_count);
774}
775static SYSDEV_ATTR(idle_count, 0444, show_idle_count, NULL);
776
777static ssize_t show_idle_time(struct sys_device *dev, char *buf)
778{
779 struct s390_idle_data *idle;
780 unsigned long long new_time;
781
782 idle = &per_cpu(s390_idle, dev->id);
783 spin_lock_irq(&idle->lock);
784 if (idle->in_idle) {
785 new_time = get_clock();
786 idle->idle_time += new_time - idle->idle_enter;
787 idle->idle_enter = new_time;
788 }
789 new_time = idle->idle_time;
790 spin_unlock_irq(&idle->lock);
Heiko Carstens69d39d62007-11-05 11:10:13 +0100791 return sprintf(buf, "%llu\n", new_time >> 12);
Heiko Carstensfae8b222007-10-22 12:52:39 +0200792}
Heiko Carstens69d39d62007-11-05 11:10:13 +0100793static SYSDEV_ATTR(idle_time_us, 0444, show_idle_time, NULL);
Heiko Carstensfae8b222007-10-22 12:52:39 +0200794
795static struct attribute *cpu_attrs[] = {
796 &attr_capability.attr,
797 &attr_idle_count.attr,
Heiko Carstens69d39d62007-11-05 11:10:13 +0100798 &attr_idle_time_us.attr,
Heiko Carstensfae8b222007-10-22 12:52:39 +0200799 NULL,
800};
801
802static struct attribute_group cpu_attr_group = {
803 .attrs = cpu_attrs,
804};
805
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200806static int __cpuinit smp_cpu_notify(struct notifier_block *self,
807 unsigned long action, void *hcpu)
808{
809 unsigned int cpu = (unsigned int)(long)hcpu;
810 struct cpu *c = &per_cpu(cpu_devices, cpu);
811 struct sys_device *s = &c->sysdev;
Heiko Carstensfae8b222007-10-22 12:52:39 +0200812 struct s390_idle_data *idle;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200813
814 switch (action) {
815 case CPU_ONLINE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700816 case CPU_ONLINE_FROZEN:
Heiko Carstensfae8b222007-10-22 12:52:39 +0200817 idle = &per_cpu(s390_idle, cpu);
818 spin_lock_irq(&idle->lock);
819 idle->idle_enter = 0;
820 idle->idle_time = 0;
821 idle->idle_count = 0;
822 spin_unlock_irq(&idle->lock);
823 if (sysfs_create_group(&s->kobj, &cpu_attr_group))
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200824 return NOTIFY_BAD;
825 break;
826 case CPU_DEAD:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700827 case CPU_DEAD_FROZEN:
Heiko Carstensfae8b222007-10-22 12:52:39 +0200828 sysfs_remove_group(&s->kobj, &cpu_attr_group);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200829 break;
830 }
831 return NOTIFY_OK;
832}
833
834static struct notifier_block __cpuinitdata smp_cpu_nb = {
Heiko Carstens39ce0102007-04-27 16:02:00 +0200835 .notifier_call = smp_cpu_notify,
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200836};
837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838static int __init topology_init(void)
839{
840 int cpu;
Heiko Carstensfae8b222007-10-22 12:52:39 +0200841 int rc;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200842
843 register_cpu_notifier(&smp_cpu_nb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
KAMEZAWA Hiroyuki97db7fb2006-03-31 02:30:26 -0800845 for_each_possible_cpu(cpu) {
Heiko Carstens6721f772007-01-09 10:18:44 +0100846 struct cpu *c = &per_cpu(cpu_devices, cpu);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200847 struct sys_device *s = &c->sysdev;
Heiko Carstens6721f772007-01-09 10:18:44 +0100848
849 c->hotpluggable = 1;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200850 register_cpu(c, cpu);
851 if (!cpu_online(cpu))
852 continue;
853 s = &c->sysdev;
Heiko Carstensfae8b222007-10-22 12:52:39 +0200854 rc = sysfs_create_group(&s->kobj, &cpu_attr_group);
855 if (rc)
856 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 }
858 return 0;
859}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860subsys_initcall(topology_init);