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