ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / base / cpu.c
1 /*
2  * drivers/base/cpu.c - basic CPU class support
3  */
4
5 #include <linux/sysdev.h>
6 #include <linux/module.h>
7 #include <linux/init.h>
8 #include <linux/cpu.h>
9 #include <linux/topology.h>
10 #include <linux/device.h>
11
12
13 struct sysdev_class cpu_sysdev_class = {
14         set_kset_name("cpu"),
15 };
16 EXPORT_SYMBOL(cpu_sysdev_class);
17
18 #ifdef CONFIG_HOTPLUG_CPU
19 static ssize_t show_online(struct sys_device *dev, char *buf)
20 {
21         struct cpu *cpu = container_of(dev, struct cpu, sysdev);
22
23         return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id));
24 }
25
26 static ssize_t store_online(struct sys_device *dev, const char *buf,
27                             size_t count)
28 {
29         struct cpu *cpu = container_of(dev, struct cpu, sysdev);
30         ssize_t ret;
31
32         switch (buf[0]) {
33         case '0':
34                 ret = cpu_down(cpu->sysdev.id);
35                 break;
36         case '1':
37                 ret = cpu_up(cpu->sysdev.id);
38                 break;
39         default:
40                 ret = -EINVAL;
41         }
42
43         if (ret >= 0)
44                 ret = count;
45         return ret;
46 }
47 static SYSDEV_ATTR(online, 0600, show_online, store_online);
48
49 static void __init register_cpu_control(struct cpu *cpu)
50 {
51         sysdev_create_file(&cpu->sysdev, &attr_online);
52 }
53 #else /* ... !CONFIG_HOTPLUG_CPU */
54 static inline void register_cpu_control(struct cpu *cpu)
55 {
56 }
57 #endif /* CONFIG_HOTPLUG_CPU */
58
59 /*
60  * register_cpu - Setup a driverfs device for a CPU.
61  * @num - CPU number to use when creating the device.
62  *
63  * Initialize and register the CPU device.
64  */
65 int __init register_cpu(struct cpu *cpu, int num, struct node *root)
66 {
67         int error;
68
69         cpu->node_id = cpu_to_node(num);
70         cpu->sysdev.id = num;
71         cpu->sysdev.cls = &cpu_sysdev_class;
72
73         error = sysdev_register(&cpu->sysdev);
74         if (!error && root)
75                 error = sysfs_create_link(&root->sysdev.kobj,
76                                           &cpu->sysdev.kobj,
77                                           kobject_name(&cpu->sysdev.kobj));
78         if (!error)
79                 register_cpu_control(cpu);
80         return error;
81 }
82
83
84
85 int __init cpu_dev_init(void)
86 {
87         return sysdev_class_register(&cpu_sysdev_class);
88 }