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>
14 struct sysdev_class cpu_sysdev_class = {
17 EXPORT_SYMBOL(cpu_sysdev_class);
19 static struct sys_device *cpu_sys_devices[NR_CPUS];
21 #ifdef CONFIG_HOTPLUG_CPU
22 static ssize_t show_online(struct sys_device *dev, char *buf)
24 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
26 return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id));
29 static ssize_t store_online(struct sys_device *dev, const char *buf,
32 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
37 ret = cpu_down(cpu->sysdev.id);
39 kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
42 ret = cpu_up(cpu->sysdev.id);
44 kobject_uevent(&dev->kobj, KOBJ_ONLINE);
54 static SYSDEV_ATTR(online, 0600, show_online, store_online);
56 static void __devinit register_cpu_control(struct cpu *cpu)
58 sysdev_create_file(&cpu->sysdev, &attr_online);
60 void unregister_cpu(struct cpu *cpu, struct node *root)
62 int logical_cpu = cpu->sysdev.id;
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);
70 cpu_sys_devices[logical_cpu] = NULL;
73 #else /* ... !CONFIG_HOTPLUG_CPU */
74 static inline void register_cpu_control(struct cpu *cpu)
77 #endif /* CONFIG_HOTPLUG_CPU */
80 #include <linux/kexec.h>
82 static ssize_t show_crash_notes(struct sys_device *dev, char *buf)
84 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
86 unsigned long long addr;
89 cpunum = cpu->sysdev.id;
92 * Might be reading other cpu's data based on which cpu read thread
93 * has been scheduled. But cpu data (memory) is allocated once during
94 * boot up and this data does not change there after. Hence this
95 * operation should be safe. No locking required.
97 addr = __pa(per_cpu_ptr(crash_notes, cpunum));
98 rc = sprintf(buf, "%Lx\n", addr);
101 static SYSDEV_ATTR(crash_notes, 0400, show_crash_notes, NULL);
105 * register_cpu - Setup a driverfs device for a CPU.
106 * @cpu - Callers can set the cpu->no_control field to 1, to indicate not to
107 * generate a control file in sysfs for this CPU.
108 * @num - CPU number to use when creating the device.
110 * Initialize and register the CPU device.
112 int __devinit register_cpu(struct cpu *cpu, int num, struct node *root)
116 cpu->node_id = cpu_to_node(num);
117 cpu->sysdev.id = num;
118 cpu->sysdev.cls = &cpu_sysdev_class;
120 error = sysdev_register(&cpu->sysdev);
122 error = sysfs_create_link(&root->sysdev.kobj,
124 kobject_name(&cpu->sysdev.kobj));
125 if (!error && !cpu->no_control)
126 register_cpu_control(cpu);
128 cpu_sys_devices[num] = &cpu->sysdev;
132 error = sysdev_create_file(&cpu->sysdev, &attr_crash_notes);
137 struct sys_device *get_cpu_sysdev(unsigned cpu)
140 return cpu_sys_devices[cpu];
144 EXPORT_SYMBOL_GPL(get_cpu_sysdev);
146 int __init cpu_dev_init(void)
148 return sysdev_class_register(&cpu_sysdev_class);