2 * drivers/base/cpu.c - basic CPU class support
5 #include <linux/sysdev.h>
6 #include <linux/module.h>
7 #include <linux/init.h>
9 #include <linux/topology.h>
10 #include <linux/device.h>
13 struct sysdev_class cpu_sysdev_class = {
16 EXPORT_SYMBOL(cpu_sysdev_class);
18 #ifdef CONFIG_HOTPLUG_CPU
19 #ifndef __HAVE_ARCH_SMP_PREPARE_CPU
20 #define smp_prepare_cpu(cpu) (0)
23 static ssize_t show_online(struct sys_device *dev, char *buf)
25 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
27 return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id));
30 static ssize_t store_online(struct sys_device *dev, const char *buf,
33 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
38 ret = cpu_down(cpu->sysdev.id);
40 kobject_hotplug(&dev->kobj, KOBJ_OFFLINE);
43 ret = smp_prepare_cpu(cpu->sysdev.id);
45 ret = cpu_up(cpu->sysdev.id);
55 static SYSDEV_ATTR(online, 0600, show_online, store_online);
57 static void __devinit register_cpu_control(struct cpu *cpu)
59 sysdev_create_file(&cpu->sysdev, &attr_online);
61 void unregister_cpu(struct cpu *cpu, struct node *root)
65 sysfs_remove_link(&root->sysdev.kobj,
66 kobject_name(&cpu->sysdev.kobj));
67 sysdev_remove_file(&cpu->sysdev, &attr_online);
69 sysdev_unregister(&cpu->sysdev);
73 #else /* ... !CONFIG_HOTPLUG_CPU */
74 static inline void register_cpu_control(struct cpu *cpu)
77 #endif /* CONFIG_HOTPLUG_CPU */
80 * register_cpu - Setup a driverfs device for a CPU.
81 * @cpu - Callers can set the cpu->no_control field to 1, to indicate not to
82 * generate a control file in sysfs for this CPU.
83 * @num - CPU number to use when creating the device.
85 * Initialize and register the CPU device.
87 int __devinit register_cpu(struct cpu *cpu, int num, struct node *root)
91 cpu->node_id = cpu_to_node(num);
93 cpu->sysdev.cls = &cpu_sysdev_class;
95 error = sysdev_register(&cpu->sysdev);
97 error = sysfs_create_link(&root->sysdev.kobj,
99 kobject_name(&cpu->sysdev.kobj));
100 if (!error && !cpu->no_control)
101 register_cpu_control(cpu);
107 int __init cpu_dev_init(void)
109 return sysdev_class_register(&cpu_sysdev_class);