2 * drivers/base/cpu.c - basic CPU class support
5 #include <linux/sysdev.h>
6 #include <linux/module.h>
7 #include <linux/init.h>
8 #include <linux/sched.h>
10 #include <linux/topology.h>
11 #include <linux/device.h>
12 #include <linux/node.h>
16 struct sysdev_class cpu_sysdev_class
= {
19 EXPORT_SYMBOL(cpu_sysdev_class
);
21 static struct sys_device
*cpu_sys_devices
[NR_CPUS
];
23 #ifdef CONFIG_HOTPLUG_CPU
24 static ssize_t
show_online(struct sys_device
*dev
, char *buf
)
26 struct cpu
*cpu
= container_of(dev
, struct cpu
, sysdev
);
28 return sprintf(buf
, "%u\n", !!cpu_online(cpu
->sysdev
.id
));
31 static ssize_t
store_online(struct sys_device
*dev
, const char *buf
,
34 struct cpu
*cpu
= container_of(dev
, struct cpu
, sysdev
);
39 ret
= cpu_down(cpu
->sysdev
.id
);
41 kobject_uevent(&dev
->kobj
, KOBJ_OFFLINE
);
44 ret
= cpu_up(cpu
->sysdev
.id
);
46 kobject_uevent(&dev
->kobj
, KOBJ_ONLINE
);
56 static SYSDEV_ATTR(online
, 0644, show_online
, store_online
);
58 static void __devinit
register_cpu_control(struct cpu
*cpu
)
60 sysdev_create_file(&cpu
->sysdev
, &attr_online
);
62 void unregister_cpu(struct cpu
*cpu
)
64 int logical_cpu
= cpu
->sysdev
.id
;
66 unregister_cpu_under_node(logical_cpu
, cpu_to_node(logical_cpu
));
68 sysdev_remove_file(&cpu
->sysdev
, &attr_online
);
70 sysdev_unregister(&cpu
->sysdev
);
71 cpu_sys_devices
[logical_cpu
] = NULL
;
74 #else /* ... !CONFIG_HOTPLUG_CPU */
75 static inline void register_cpu_control(struct cpu
*cpu
)
78 #endif /* CONFIG_HOTPLUG_CPU */
81 #include <linux/kexec.h>
83 static ssize_t
show_crash_notes(struct sys_device
*dev
, char *buf
)
85 struct cpu
*cpu
= container_of(dev
, struct cpu
, sysdev
);
87 unsigned long long addr
;
90 cpunum
= cpu
->sysdev
.id
;
93 * Might be reading other cpu's data based on which cpu read thread
94 * has been scheduled. But cpu data (memory) is allocated once during
95 * boot up and this data does not change there after. Hence this
96 * operation should be safe. No locking required.
98 addr
= __pa(per_cpu_ptr(crash_notes
, cpunum
));
99 rc
= sprintf(buf
, "%Lx\n", addr
);
102 static SYSDEV_ATTR(crash_notes
, 0400, show_crash_notes
, NULL
);
106 * register_cpu - Setup a sysfs device for a CPU.
107 * @cpu - cpu->hotpluggable field set to 1 will generate a control file in
108 * sysfs for this CPU.
109 * @num - CPU number to use when creating the device.
111 * Initialize and register the CPU device.
113 int __devinit
register_cpu(struct cpu
*cpu
, int num
)
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 if (!error
&& cpu
->hotpluggable
)
123 register_cpu_control(cpu
);
125 cpu_sys_devices
[num
] = &cpu
->sysdev
;
127 register_cpu_under_node(num
, cpu_to_node(num
));
131 error
= sysdev_create_file(&cpu
->sysdev
, &attr_crash_notes
);
136 struct sys_device
*get_cpu_sysdev(unsigned cpu
)
139 return cpu_sys_devices
[cpu
];
143 EXPORT_SYMBOL_GPL(get_cpu_sysdev
);
145 int __init
cpu_dev_init(void)
149 err
= sysdev_class_register(&cpu_sysdev_class
);
150 #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT)
152 err
= sched_create_sysfs_power_savings_entries(&cpu_sysdev_class
);