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