Merge tag 'v3.10.55' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / xen / cpu_hotplug.c
CommitLineData
d68d82af
AN
1#include <linux/notifier.h>
2
1ccbf534 3#include <xen/xen.h>
d68d82af
AN
4#include <xen/xenbus.h>
5
bb898558 6#include <asm/xen/hypervisor.h>
d68d82af
AN
7#include <asm/cpu.h>
8
9static void enable_hotplug_cpu(int cpu)
10{
11 if (!cpu_present(cpu))
12 arch_register_cpu(cpu);
13
d680eb8b 14 set_cpu_present(cpu, true);
d68d82af
AN
15}
16
17static void disable_hotplug_cpu(int cpu)
18{
19 if (cpu_present(cpu))
20 arch_unregister_cpu(cpu);
21
d680eb8b 22 set_cpu_present(cpu, false);
d68d82af
AN
23}
24
d745562c 25static int vcpu_online(unsigned int cpu)
d68d82af
AN
26{
27 int err;
e5c702d3 28 char dir[16], state[16];
d68d82af 29
d68d82af 30 sprintf(dir, "cpu/%u", cpu);
e5c702d3 31 err = xenbus_scanf(XBT_NIL, dir, "availability", "%15s", state);
d68d82af 32 if (err != 1) {
5b02aa1e
KRW
33 if (!xen_initial_domain())
34 printk(KERN_ERR "XENBUS: Unable to read cpu state\n");
d745562c 35 return err;
d68d82af
AN
36 }
37
d745562c
IC
38 if (strcmp(state, "online") == 0)
39 return 1;
40 else if (strcmp(state, "offline") == 0)
41 return 0;
42
43 printk(KERN_ERR "XENBUS: unknown state(%s) on CPU%d\n", state, cpu);
44 return -EINVAL;
45}
46static void vcpu_hotplug(unsigned int cpu)
47{
48 if (!cpu_possible(cpu))
49 return;
50
51 switch (vcpu_online(cpu)) {
52 case 1:
d68d82af 53 enable_hotplug_cpu(cpu);
d745562c
IC
54 break;
55 case 0:
d68d82af
AN
56 (void)cpu_down(cpu);
57 disable_hotplug_cpu(cpu);
d745562c
IC
58 break;
59 default:
60 break;
d68d82af
AN
61 }
62}
63
64static void handle_vcpu_hotplug_event(struct xenbus_watch *watch,
65 const char **vec, unsigned int len)
66{
67 unsigned int cpu;
68 char *cpustr;
69 const char *node = vec[XS_WATCH_PATH];
70
71 cpustr = strstr(node, "cpu/");
72 if (cpustr != NULL) {
73 sscanf(cpustr, "cpu/%u", &cpu);
74 vcpu_hotplug(cpu);
75 }
76}
77
78static int setup_cpu_watcher(struct notifier_block *notifier,
79 unsigned long event, void *data)
80{
d745562c 81 int cpu;
d68d82af
AN
82 static struct xenbus_watch cpu_watch = {
83 .node = "cpu",
84 .callback = handle_vcpu_hotplug_event};
85
86 (void)register_xenbus_watch(&cpu_watch);
87
d745562c
IC
88 for_each_possible_cpu(cpu) {
89 if (vcpu_online(cpu) == 0) {
90 (void)cpu_down(cpu);
d7d3756c 91 set_cpu_present(cpu, false);
d745562c
IC
92 }
93 }
94
d68d82af
AN
95 return NOTIFY_DONE;
96}
97
98static int __init setup_vcpu_hotplug_event(void)
99{
100 static struct notifier_block xsn_cpu = {
101 .notifier_call = setup_cpu_watcher };
102
5c51c637 103 if (!xen_pv_domain())
d68d82af
AN
104 return -ENODEV;
105
106 register_xenstore_notifier(&xsn_cpu);
107
108 return 0;
109}
110
111arch_initcall(setup_vcpu_hotplug_event);
112