2 * pseries CPU Hotplug infrastructure.
4 * Split out from arch/powerpc/platforms/pseries/setup.c
5 * arch/powerpc/kernel/rtas.c, and arch/powerpc/platforms/pseries/smp.c
7 * Peter Bergner, IBM March 2001.
8 * Copyright (C) 2001 IBM.
9 * Dave Engebretsen, Peter Bergner, and
10 * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
11 * Plus various changes from other IBM teams...
13 * Copyright (C) 2006 Michael Ellerman, IBM Corporation
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
21 #include <linux/kernel.h>
22 #include <linux/delay.h>
23 #include <linux/cpu.h>
24 #include <asm/system.h>
27 #include <asm/firmware.h>
28 #include <asm/machdep.h>
29 #include <asm/vdso_datapage.h>
30 #include <asm/pSeries_reconfig.h>
32 #include "plpar_wrappers.h"
34 /* This version can't take the spinlock, because it never returns */
35 static struct rtas_args rtas_stop_self_args
= {
36 .token
= RTAS_UNKNOWN_SERVICE
,
39 .rets
= &rtas_stop_self_args
.args
[0],
42 static void rtas_stop_self(void)
44 struct rtas_args
*args
= &rtas_stop_self_args
;
48 BUG_ON(args
->token
== RTAS_UNKNOWN_SERVICE
);
50 printk("cpu %u (hwid %u) Ready to die...\n",
51 smp_processor_id(), hard_smp_processor_id());
52 enter_rtas(__pa(args
));
54 panic("Alas, I survived.\n");
57 static void pseries_mach_cpu_die(void)
62 unregister_slb_shadow(hard_smp_processor_id(), __pa(get_slb_shadow()));
64 /* Should never get here... */
69 static int pseries_cpu_disable(void)
71 int cpu
= smp_processor_id();
73 set_cpu_online(cpu
, false);
74 vdso_data
->processorCount
--;
76 /*fix boot_cpuid here*/
77 if (cpu
== boot_cpuid
)
78 boot_cpuid
= any_online_cpu(cpu_online_map
);
80 /* FIXME: abstract this to not be platform specific later on */
81 xics_migrate_irqs_away();
85 static void pseries_cpu_die(unsigned int cpu
)
89 unsigned int pcpu
= get_hard_smp_processor_id(cpu
);
91 for (tries
= 0; tries
< 25; tries
++) {
92 cpu_status
= smp_query_cpu_stopped(pcpu
);
93 if (cpu_status
== QCSS_STOPPED
||
94 cpu_status
== QCSS_HARDWARE_ERROR
)
98 if (cpu_status
!= 0) {
99 printk("Querying DEAD? cpu %i (%i) shows %i\n",
100 cpu
, pcpu
, cpu_status
);
103 /* Isolation and deallocation are definatly done by
104 * drslot_chrp_cpu. If they were not they would be
105 * done here. Change isolate state to Isolate and
106 * change allocation-state to Unusable.
108 paca
[cpu
].cpu_start
= 0;
112 * Update cpu_present_map and paca(s) for a new cpu node. The wrinkle
113 * here is that a cpu device node may represent up to two logical cpus
114 * in the SMT case. We must honor the assumption in other code that
115 * the logical ids for sibling SMT threads x and y are adjacent, such
116 * that x^1 == y and y^1 == x.
118 static int pseries_add_processor(struct device_node
*np
)
121 cpumask_t candidate_map
, tmp
= CPU_MASK_NONE
;
122 int err
= -ENOSPC
, len
, nthreads
, i
;
125 intserv
= of_get_property(np
, "ibm,ppc-interrupt-server#s", &len
);
129 nthreads
= len
/ sizeof(u32
);
130 for (i
= 0; i
< nthreads
; i
++)
133 cpu_maps_update_begin();
135 BUG_ON(!cpus_subset(cpu_present_map
, cpu_possible_map
));
137 /* Get a bitmap of unoccupied slots. */
138 cpus_xor(candidate_map
, cpu_possible_map
, cpu_present_map
);
139 if (cpus_empty(candidate_map
)) {
140 /* If we get here, it most likely means that NR_CPUS is
141 * less than the partition's max processors setting.
143 printk(KERN_ERR
"Cannot add cpu %s; this system configuration"
144 " supports %d logical cpus.\n", np
->full_name
,
145 cpus_weight(cpu_possible_map
));
149 while (!cpus_empty(tmp
))
150 if (cpus_subset(tmp
, candidate_map
))
151 /* Found a range where we can insert the new cpu(s) */
154 cpus_shift_left(tmp
, tmp
, nthreads
);
156 if (cpus_empty(tmp
)) {
157 printk(KERN_ERR
"Unable to find space in cpu_present_map for"
158 " processor %s with %d thread(s)\n", np
->name
,
163 for_each_cpu_mask(cpu
, tmp
) {
164 BUG_ON(cpu_isset(cpu
, cpu_present_map
));
165 set_cpu_present(cpu
, true);
166 set_hard_smp_processor_id(cpu
, *intserv
++);
170 cpu_maps_update_done();
175 * Update the present map for a cpu node which is going away, and set
176 * the hard id in the paca(s) to -1 to be consistent with boot time
177 * convention for non-present cpus.
179 static void pseries_remove_processor(struct device_node
*np
)
182 int len
, nthreads
, i
;
185 intserv
= of_get_property(np
, "ibm,ppc-interrupt-server#s", &len
);
189 nthreads
= len
/ sizeof(u32
);
191 cpu_maps_update_begin();
192 for (i
= 0; i
< nthreads
; i
++) {
193 for_each_present_cpu(cpu
) {
194 if (get_hard_smp_processor_id(cpu
) != intserv
[i
])
196 BUG_ON(cpu_online(cpu
));
197 set_cpu_present(cpu
, false);
198 set_hard_smp_processor_id(cpu
, -1);
202 printk(KERN_WARNING
"Could not find cpu to remove "
203 "with physical id 0x%x\n", intserv
[i
]);
205 cpu_maps_update_done();
208 static int pseries_smp_notifier(struct notifier_block
*nb
,
209 unsigned long action
, void *node
)
214 case PSERIES_RECONFIG_ADD
:
215 if (pseries_add_processor(node
))
218 case PSERIES_RECONFIG_REMOVE
:
219 pseries_remove_processor(node
);
228 static struct notifier_block pseries_smp_nb
= {
229 .notifier_call
= pseries_smp_notifier
,
232 static int __init
pseries_cpu_hotplug_init(void)
234 struct device_node
*np
;
238 for_each_node_by_name(np
, "interrupt-controller") {
239 typep
= of_get_property(np
, "compatible", NULL
);
240 if (strstr(typep
, "open-pic")) {
243 printk(KERN_INFO
"CPU Hotplug not supported on "
244 "systems using MPIC\n");
249 rtas_stop_self_args
.token
= rtas_token("stop-self");
250 qcss_tok
= rtas_token("query-cpu-stopped-state");
252 if (rtas_stop_self_args
.token
== RTAS_UNKNOWN_SERVICE
||
253 qcss_tok
== RTAS_UNKNOWN_SERVICE
) {
254 printk(KERN_INFO
"CPU Hotplug not supported by firmware "
259 ppc_md
.cpu_die
= pseries_mach_cpu_die
;
260 smp_ops
->cpu_disable
= pseries_cpu_disable
;
261 smp_ops
->cpu_die
= pseries_cpu_die
;
263 /* Processors can be added/removed only on LPAR */
264 if (firmware_has_feature(FW_FEATURE_LPAR
))
265 pSeries_reconfig_notifier_register(&pseries_smp_nb
);
269 arch_initcall(pseries_cpu_hotplug_init
);