Merge remote-tracking branch 'lightnvm/for-next'
[deliverable/linux.git] / drivers / acpi / processor_driver.c
CommitLineData
1da177e4 1/*
ac212b69 2 * processor_driver.c - ACPI Processor Driver
1da177e4
LT
3 *
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
ac212b69
RW
9 * Copyright (C) 2013, Intel Corporation
10 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1da177e4
LT
11 *
12 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 *
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.
18 *
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.
23 *
1da177e4 24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1da177e4
LT
25 */
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
1da177e4
LT
30#include <linux/cpufreq.h>
31#include <linux/cpu.h>
4f86d3a8 32#include <linux/cpuidle.h>
5a0e3ad6 33#include <linux/slab.h>
47db4547 34#include <linux/acpi.h>
ac212b69 35
1da177e4
LT
36#include <acpi/processor.h>
37
ac212b69
RW
38#include "internal.h"
39
1da177e4
LT
40#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
41#define ACPI_PROCESSOR_NOTIFY_POWER 0x81
01854e69 42#define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82
1da177e4 43
1da177e4 44#define _COMPONENT ACPI_PROCESSOR_COMPONENT
0131aa3d 45ACPI_MODULE_NAME("processor_driver");
1da177e4 46
f52fd66d 47MODULE_AUTHOR("Paul Diefenbaugh");
7cda93e0 48MODULE_DESCRIPTION("ACPI Processor Driver");
1da177e4
LT
49MODULE_LICENSE("GPL");
50
ac212b69
RW
51static int acpi_processor_start(struct device *dev);
52static int acpi_processor_stop(struct device *dev);
1da177e4 53
1ba90e3a 54static const struct acpi_device_id processor_device_ids[] = {
ad93a765 55 {ACPI_PROCESSOR_OBJECT_HID, 0},
9f324bda 56 {ACPI_PROCESSOR_DEVICE_HID, 0},
1ba90e3a
TR
57 {"", 0},
58};
59MODULE_DEVICE_TABLE(acpi, processor_device_ids);
60
ac212b69 61static struct device_driver acpi_processor_driver = {
c2b6705b 62 .name = "processor",
ac212b69
RW
63 .bus = &cpu_subsys,
64 .acpi_match_table = processor_device_ids,
65 .probe = acpi_processor_start,
66 .remove = acpi_processor_stop,
1da177e4
LT
67};
68
ac212b69 69static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
1da177e4 70{
ac212b69 71 struct acpi_device *device = data;
b26e9286 72 struct acpi_processor *pr;
e790cc8b 73 int saved;
1da177e4 74
ac212b69
RW
75 if (device->handle != handle)
76 return;
77
78 pr = acpi_driver_data(device);
1da177e4 79 if (!pr)
d550d98d 80 return;
1da177e4 81
1da177e4
LT
82 switch (event) {
83 case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
e790cc8b 84 saved = pr->performance_platform_limit;
d81c45e1 85 acpi_processor_ppc_has_changed(pr, 1);
e790cc8b
AS
86 if (saved == pr->performance_platform_limit)
87 break;
962ce8ca 88 acpi_bus_generate_netlink_event(device->pnp.device_class,
0794469d 89 dev_name(&device->dev), event,
962ce8ca 90 pr->performance_platform_limit);
1da177e4
LT
91 break;
92 case ACPI_PROCESSOR_NOTIFY_POWER:
a36a7fec 93 acpi_processor_power_state_has_changed(pr);
962ce8ca 94 acpi_bus_generate_netlink_event(device->pnp.device_class,
0794469d 95 dev_name(&device->dev), event, 0);
1da177e4 96 break;
01854e69
LY
97 case ACPI_PROCESSOR_NOTIFY_THROTTLING:
98 acpi_processor_tstate_has_changed(pr);
962ce8ca 99 acpi_bus_generate_netlink_event(device->pnp.device_class,
0794469d 100 dev_name(&device->dev), event, 0);
879dca01 101 break;
1da177e4
LT
102 default:
103 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
4be44fcd 104 "Unsupported event [0x%x]\n", event));
1da177e4
LT
105 break;
106 }
107
d550d98d 108 return;
1da177e4
LT
109}
110
fe7bf106 111static int __acpi_processor_start(struct acpi_device *device);
ac212b69 112
fe7bf106 113static int acpi_cpu_soft_notify(struct notifier_block *nfb,
ac212b69 114 unsigned long action, void *hcpu)
729c6ba3
VP
115{
116 unsigned int cpu = (unsigned long)hcpu;
706546d0 117 struct acpi_processor *pr = per_cpu(processors, cpu);
ac212b69 118 struct acpi_device *device;
ea9c167d 119 action &= ~CPU_TASKS_FROZEN;
729c6ba3 120
e1272f54
RC
121 switch (action) {
122 case CPU_ONLINE:
123 case CPU_DEAD:
124 break;
125 default:
8da83734 126 return NOTIFY_DONE;
e1272f54 127 }
8da83734 128
ac212b69
RW
129 if (!pr || acpi_bus_get_device(pr->handle, &device))
130 return NOTIFY_DONE;
131
132 if (action == CPU_ONLINE) {
133 /*
134 * CPU got physically hotplugged and onlined for the first time:
135 * Initialize missing things.
99b72508
TR
136 */
137 if (pr->flags.need_hotplug_init) {
ac212b69
RW
138 int ret;
139
47db4547
TK
140 pr_info("Will online and init hotplugged CPU: %d\n",
141 pr->id);
99b72508 142 pr->flags.need_hotplug_init = 0;
ac212b69
RW
143 ret = __acpi_processor_start(device);
144 WARN(ret, "Failed to start CPU: %d\n", pr->id);
99b72508 145 } else {
ac212b69 146 /* Normal CPU soft online event. */
99b72508 147 acpi_processor_ppc_has_changed(pr, 0);
b7db60f4 148 acpi_processor_hotplug(pr);
99b72508
TR
149 acpi_processor_reevaluate_tstate(pr, action);
150 acpi_processor_tstate_has_changed(pr);
151 }
ac212b69
RW
152 } else if (action == CPU_DEAD) {
153 /* Invalidate flag.throttling after the CPU is offline. */
5a344a50
ZY
154 acpi_processor_reevaluate_tstate(pr, action);
155 }
729c6ba3
VP
156 return NOTIFY_OK;
157}
158
8ce344c6 159static struct notifier_block acpi_cpu_notifier = {
729c6ba3
VP
160 .notifier_call = acpi_cpu_soft_notify,
161};
162
239708a3
AC
163#ifdef CONFIG_ACPI_CPU_FREQ_PSS
164static int acpi_pss_perf_init(struct acpi_processor *pr,
165 struct acpi_device *device)
54d5dcc4 166{
54d5dcc4
TR
167 int result = 0;
168
54d5dcc4 169 acpi_processor_ppc_has_changed(pr, 0);
239708a3 170
54d5dcc4 171 acpi_processor_get_throttling_info(pr);
22e7551e
LT
172
173 if (pr->flags.throttling)
174 pr->flags.limit = 1;
54d5dcc4 175
54d5dcc4
TR
176 pr->cdev = thermal_cooling_device_register("Processor", device,
177 &processor_cooling_ops);
178 if (IS_ERR(pr->cdev)) {
179 result = PTR_ERR(pr->cdev);
239708a3 180 return result;
54d5dcc4
TR
181 }
182
183 dev_dbg(&device->dev, "registered as cooling_device%d\n",
184 pr->cdev->id);
185
186 result = sysfs_create_link(&device->dev.kobj,
187 &pr->cdev->device.kobj,
188 "thermal_cooling");
189 if (result) {
47db4547
TK
190 dev_err(&device->dev,
191 "Failed to create sysfs link 'thermal_cooling'\n");
54d5dcc4
TR
192 goto err_thermal_unregister;
193 }
239708a3 194
54d5dcc4
TR
195 result = sysfs_create_link(&pr->cdev->device.kobj,
196 &device->dev.kobj,
197 "device");
198 if (result) {
47db4547
TK
199 dev_err(&pr->cdev->device,
200 "Failed to create sysfs link 'device'\n");
54d5dcc4
TR
201 goto err_remove_sysfs_thermal;
202 }
203
ce360db7
SP
204 return 0;
205
ac212b69 206 err_remove_sysfs_thermal:
54d5dcc4 207 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
ac212b69 208 err_thermal_unregister:
54d5dcc4 209 thermal_cooling_device_unregister(pr->cdev);
239708a3
AC
210
211 return result;
212}
213
214static void acpi_pss_perf_exit(struct acpi_processor *pr,
215 struct acpi_device *device)
216{
217 if (pr->cdev) {
218 sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
219 sysfs_remove_link(&pr->cdev->device.kobj, "device");
220 thermal_cooling_device_unregister(pr->cdev);
221 pr->cdev = NULL;
222 }
223}
224#else
225static inline int acpi_pss_perf_init(struct acpi_processor *pr,
226 struct acpi_device *device)
227{
228 return 0;
229}
230
231static inline void acpi_pss_perf_exit(struct acpi_processor *pr,
232 struct acpi_device *device) {}
233#endif /* CONFIG_ACPI_CPU_FREQ_PSS */
234
235static int __acpi_processor_start(struct acpi_device *device)
236{
237 struct acpi_processor *pr = acpi_driver_data(device);
238 acpi_status status;
239 int result = 0;
240
241 if (!pr)
242 return -ENODEV;
243
244 if (pr->flags.need_hotplug_init)
245 return 0;
246
4f2f7573 247 result = acpi_cppc_processor_probe(pr);
65e95891 248 if (result && !IS_ENABLED(CONFIG_ACPI_CPU_FREQ_PSS))
5448f146 249 dev_warn(&device->dev, "CPPC data invalid or not present\n");
4f2f7573 250
239708a3
AC
251 if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
252 acpi_processor_power_init(pr);
253
254 result = acpi_pss_perf_init(pr, device);
255 if (result)
256 goto err_power_exit;
257
258 status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
259 acpi_processor_notify, device);
260 if (ACPI_SUCCESS(status))
261 return 0;
262
263err_power_exit:
38a991b6 264 acpi_processor_power_exit(pr);
54d5dcc4
TR
265 return result;
266}
267
fe7bf106 268static int acpi_processor_start(struct device *dev)
1da177e4 269{
d0a7edbb 270 struct acpi_device *device = ACPI_COMPANION(dev);
1da177e4 271
d0a7edbb 272 if (!device)
ac212b69 273 return -ENODEV;
1da177e4 274
ac212b69 275 return __acpi_processor_start(device);
1da177e4
LT
276}
277
ac212b69 278static int acpi_processor_stop(struct device *dev)
1da177e4 279{
d0a7edbb 280 struct acpi_device *device = ACPI_COMPANION(dev);
ac212b69 281 struct acpi_processor *pr;
1da177e4 282
d0a7edbb 283 if (!device)
ac212b69 284 return 0;
1da177e4 285
ac212b69
RW
286 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
287 acpi_processor_notify);
1da177e4 288
50dd0969 289 pr = acpi_driver_data(device);
ac212b69
RW
290 if (!pr)
291 return 0;
38a991b6 292 acpi_processor_power_exit(pr);
1da177e4 293
239708a3
AC
294 acpi_pss_perf_exit(pr, device);
295
4f2f7573
AC
296 acpi_cppc_processor_exit(pr);
297
d550d98d 298 return 0;
1da177e4
LT
299}
300
1da177e4
LT
301/*
302 * We keep the driver loaded even when ACPI is not running.
303 * This is needed for the powernow-k8 driver, that works even without
304 * ACPI, but needs symbols from this driver
305 */
306
ac212b69 307static int __init acpi_processor_driver_init(void)
1da177e4 308{
4be44fcd 309 int result = 0;
1da177e4 310
ce8442b5
YL
311 if (acpi_disabled)
312 return 0;
313
ac212b69 314 result = driver_register(&acpi_processor_driver);
4f86d3a8 315 if (result < 0)
46bcfad7 316 return result;
1da177e4 317
ac212b69 318 register_hotcpu_notifier(&acpi_cpu_notifier);
1da177e4 319 acpi_thermal_cpufreq_init();
1da177e4 320 acpi_processor_ppc_init();
1180509f 321 acpi_processor_throttling_init();
d550d98d 322 return 0;
1da177e4
LT
323}
324
ac212b69 325static void __exit acpi_processor_driver_exit(void)
1da177e4 326{
ce8442b5
YL
327 if (acpi_disabled)
328 return;
329
1da177e4 330 acpi_processor_ppc_exit();
1da177e4 331 acpi_thermal_cpufreq_exit();
ac212b69 332 unregister_hotcpu_notifier(&acpi_cpu_notifier);
ac212b69 333 driver_unregister(&acpi_processor_driver);
1da177e4
LT
334}
335
ac212b69
RW
336module_init(acpi_processor_driver_init);
337module_exit(acpi_processor_driver_exit);
1da177e4 338
1da177e4 339MODULE_ALIAS("processor");
This page took 0.938268 seconds and 5 git commands to generate.