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 static ssize_t show_online(struct sys_device *dev, char *buf)
21 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
23 return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id));
26 static ssize_t store_online(struct sys_device *dev, const char *buf,
29 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
34 ret = cpu_down(cpu->sysdev.id);
37 ret = cpu_up(cpu->sysdev.id);
47 static SYSDEV_ATTR(online, 0600, show_online, store_online);
49 static void __init register_cpu_control(struct cpu *cpu)
51 sysdev_create_file(&cpu->sysdev, &attr_online);
53 #else /* ... !CONFIG_HOTPLUG_CPU */
54 static inline void register_cpu_control(struct cpu *cpu)
57 #endif /* CONFIG_HOTPLUG_CPU */
60 * register_cpu - Setup a driverfs device for a CPU.
61 * @cpu - Callers can set the cpu->no_control field to 1, to indicate not to
62 * generate a control file in sysfs for this CPU.
63 * @num - CPU number to use when creating the device.
65 * Initialize and register the CPU device.
67 int __init register_cpu(struct cpu *cpu, int num, struct node *root)
71 cpu->node_id = cpu_to_node(num);
73 cpu->sysdev.cls = &cpu_sysdev_class;
75 error = sysdev_register(&cpu->sysdev);
77 error = sysfs_create_link(&root->sysdev.kobj,
79 kobject_name(&cpu->sysdev.kobj));
80 if (!error && !cpu->no_control)
81 register_cpu_control(cpu);
87 int __init cpu_dev_init(void)
89 return sysdev_class_register(&cpu_sysdev_class);