2 * processor_driver.c - ACPI Processor Driver
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de>
7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 * - Added processor hotplug support
9 * Copyright (C) 2013, Intel Corporation
10 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
12 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or (at
17 * your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/init.h>
34 #include <linux/cpufreq.h>
35 #include <linux/cpu.h>
36 #include <linux/cpuidle.h>
37 #include <linux/slab.h>
38 #include <linux/acpi.h>
40 #include <acpi/processor.h>
44 #define PREFIX "ACPI: "
46 #define ACPI_PROCESSOR_FILE_INFO "info"
47 #define ACPI_PROCESSOR_FILE_THROTTLING "throttling"
48 #define ACPI_PROCESSOR_FILE_LIMIT "limit"
49 #define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
50 #define ACPI_PROCESSOR_NOTIFY_POWER 0x81
51 #define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82
53 #define ACPI_PROCESSOR_LIMIT_USER 0
54 #define ACPI_PROCESSOR_LIMIT_THERMAL 1
56 #define _COMPONENT ACPI_PROCESSOR_COMPONENT
57 ACPI_MODULE_NAME("processor_driver");
59 MODULE_AUTHOR("Paul Diefenbaugh");
60 MODULE_DESCRIPTION("ACPI Processor Driver");
61 MODULE_LICENSE("GPL");
63 static int acpi_processor_start(struct device *dev);
64 static int acpi_processor_stop(struct device *dev);
66 static const struct acpi_device_id processor_device_ids[] = {
67 {ACPI_PROCESSOR_OBJECT_HID, 0},
68 {ACPI_PROCESSOR_DEVICE_HID, 0},
71 MODULE_DEVICE_TABLE(acpi, processor_device_ids);
73 static struct device_driver acpi_processor_driver = {
76 .acpi_match_table = processor_device_ids,
77 .probe = acpi_processor_start,
78 .remove = acpi_processor_stop,
81 static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
83 struct acpi_device *device = data;
84 struct acpi_processor *pr;
87 if (device->handle != handle)
90 pr = acpi_driver_data(device);
95 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
96 saved = pr->performance_platform_limit;
97 acpi_processor_ppc_has_changed(pr, 1);
98 if (saved == pr->performance_platform_limit)
100 acpi_bus_generate_proc_event(device, event,
101 pr->performance_platform_limit);
102 acpi_bus_generate_netlink_event(device->pnp.device_class,
103 dev_name(&device->dev), event,
104 pr->performance_platform_limit);
106 case ACPI_PROCESSOR_NOTIFY_POWER:
107 acpi_processor_cst_has_changed(pr);
108 acpi_bus_generate_proc_event(device, event, 0);
109 acpi_bus_generate_netlink_event(device->pnp.device_class,
110 dev_name(&device->dev), event, 0);
112 case ACPI_PROCESSOR_NOTIFY_THROTTLING:
113 acpi_processor_tstate_has_changed(pr);
114 acpi_bus_generate_proc_event(device, event, 0);
115 acpi_bus_generate_netlink_event(device->pnp.device_class,
116 dev_name(&device->dev), event, 0);
119 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
120 "Unsupported event [0x%x]\n", event));
127 static __cpuinit int __acpi_processor_start(struct acpi_device *device);
129 static int __cpuinit acpi_cpu_soft_notify(struct notifier_block *nfb,
130 unsigned long action, void *hcpu)
132 unsigned int cpu = (unsigned long)hcpu;
133 struct acpi_processor *pr = per_cpu(processors, cpu);
134 struct acpi_device *device;
136 if (!pr || acpi_bus_get_device(pr->handle, &device))
139 if (action == CPU_ONLINE) {
141 * CPU got physically hotplugged and onlined for the first time:
142 * Initialize missing things.
144 if (pr->flags.need_hotplug_init) {
147 pr_info("Will online and init hotplugged CPU: %d\n",
149 pr->flags.need_hotplug_init = 0;
150 ret = __acpi_processor_start(device);
151 WARN(ret, "Failed to start CPU: %d\n", pr->id);
153 /* Normal CPU soft online event. */
154 acpi_processor_ppc_has_changed(pr, 0);
155 acpi_processor_hotplug(pr);
156 acpi_processor_reevaluate_tstate(pr, action);
157 acpi_processor_tstate_has_changed(pr);
159 } else if (action == CPU_DEAD) {
160 /* Invalidate flag.throttling after the CPU is offline. */
161 acpi_processor_reevaluate_tstate(pr, action);
166 static struct notifier_block __refdata acpi_cpu_notifier =
168 .notifier_call = acpi_cpu_soft_notify,
171 static __cpuinit int __acpi_processor_start(struct acpi_device *device)
173 struct acpi_processor *pr = acpi_driver_data(device);
180 if (pr->flags.need_hotplug_init)
183 #ifdef CONFIG_CPU_FREQ
184 acpi_processor_ppc_has_changed(pr, 0);
185 acpi_processor_load_module(pr);
187 acpi_processor_get_throttling_info(pr);
188 acpi_processor_get_limit_info(pr);
190 if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
191 acpi_processor_power_init(pr);
193 pr->cdev = thermal_cooling_device_register("Processor", device,
194 &processor_cooling_ops);
195 if (IS_ERR(pr->cdev)) {
196 result = PTR_ERR(pr->cdev);
200 dev_dbg(&device->dev, "registered as cooling_device%d\n",
203 result = sysfs_create_link(&device->dev.kobj,
204 &pr->cdev->device.kobj,
207 dev_err(&device->dev,
208 "Failed to create sysfs link 'thermal_cooling'\n");
209 goto err_thermal_unregister;
211 result = sysfs_create_link(&pr->cdev->device.kobj,
215 dev_err(&pr->cdev->device,
216 "Failed to create sysfs link 'device'\n");
217 goto err_remove_sysfs_thermal;
220 status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
221 acpi_processor_notify, device);
222 if (ACPI_SUCCESS(status))
225 sysfs_remove_link(&pr->cdev->device.kobj, "device");
226 err_remove_sysfs_thermal:
227 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
228 err_thermal_unregister:
229 thermal_cooling_device_unregister(pr->cdev);
231 acpi_processor_power_exit(pr);
235 static int __cpuinit acpi_processor_start(struct device *dev)
237 struct acpi_device *device;
239 if (acpi_bus_get_device(ACPI_HANDLE(dev), &device))
242 return __acpi_processor_start(device);
245 static int acpi_processor_stop(struct device *dev)
247 struct acpi_device *device;
248 struct acpi_processor *pr;
250 if (acpi_bus_get_device(ACPI_HANDLE(dev), &device))
253 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
254 acpi_processor_notify);
256 pr = acpi_driver_data(device);
260 acpi_processor_power_exit(pr);
263 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
264 sysfs_remove_link(&pr->cdev->device.kobj, "device");
265 thermal_cooling_device_unregister(pr->cdev);
272 * We keep the driver loaded even when ACPI is not running.
273 * This is needed for the powernow-k8 driver, that works even without
274 * ACPI, but needs symbols from this driver
277 static int __init acpi_processor_driver_init(void)
284 result = driver_register(&acpi_processor_driver);
288 acpi_processor_syscore_init();
289 register_hotcpu_notifier(&acpi_cpu_notifier);
290 acpi_thermal_cpufreq_init();
291 acpi_processor_ppc_init();
292 acpi_processor_throttling_init();
296 static void __exit acpi_processor_driver_exit(void)
301 acpi_processor_ppc_exit();
302 acpi_thermal_cpufreq_exit();
303 unregister_hotcpu_notifier(&acpi_cpu_notifier);
304 acpi_processor_syscore_exit();
305 driver_unregister(&acpi_processor_driver);
308 module_init(acpi_processor_driver_init);
309 module_exit(acpi_processor_driver_exit);
311 MODULE_ALIAS("processor");