Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 3 | * processor_driver.c - ACPI Processor Driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
| 6 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
| 7 | * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de> |
| 8 | * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> |
| 9 | * - Added processor hotplug support |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 10 | * Copyright (C) 2013, Intel Corporation |
| 11 | * Rafael J. Wysocki <rafael.j.wysocki@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/cpufreq.h> |
| 18 | #include <linux/cpu.h> |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 19 | #include <linux/cpuidle.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Toshi Kani | 47db454 | 2012-11-20 23:42:27 +0000 | [diff] [blame] | 21 | #include <linux/acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <acpi/processor.h> |
| 24 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 25 | #include "internal.h" |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80 |
| 28 | #define ACPI_PROCESSOR_NOTIFY_POWER 0x81 |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 29 | #define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT |
Alex Chiang | 0131aa3 | 2010-02-22 12:11:08 -0700 | [diff] [blame] | 32 | ACPI_MODULE_NAME("processor_driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 34 | MODULE_AUTHOR("Paul Diefenbaugh"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 35 | MODULE_DESCRIPTION("ACPI Processor Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | MODULE_LICENSE("GPL"); |
| 37 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 38 | static int acpi_processor_start(struct device *dev); |
| 39 | static int acpi_processor_stop(struct device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 41 | static const struct acpi_device_id processor_device_ids[] = { |
Myron Stowe | ad93a76 | 2008-11-04 14:52:55 -0700 | [diff] [blame] | 42 | {ACPI_PROCESSOR_OBJECT_HID, 0}, |
Toshi Kani | 9f324bd | 2012-03-19 13:08:02 -0600 | [diff] [blame] | 43 | {ACPI_PROCESSOR_DEVICE_HID, 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 44 | {"", 0}, |
| 45 | }; |
| 46 | MODULE_DEVICE_TABLE(acpi, processor_device_ids); |
| 47 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 48 | static struct device_driver acpi_processor_driver = { |
Len Brown | c2b6705 | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 49 | .name = "processor", |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 50 | .bus = &cpu_subsys, |
| 51 | .acpi_match_table = processor_device_ids, |
| 52 | .probe = acpi_processor_start, |
| 53 | .remove = acpi_processor_stop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 56 | static void acpi_processor_notify(acpi_handle handle, u32 event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 58 | struct acpi_device *device = data; |
Myron Stowe | b26e928 | 2008-11-04 14:53:00 -0700 | [diff] [blame] | 59 | struct acpi_processor *pr; |
Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 60 | int saved; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 62 | if (device->handle != handle) |
| 63 | return; |
| 64 | |
| 65 | pr = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 67 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | switch (event) { |
| 70 | case ACPI_PROCESSOR_NOTIFY_PERFORMANCE: |
Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 71 | saved = pr->performance_platform_limit; |
Zhao Yakui | d81c45e1 | 2009-10-16 09:20:41 +0800 | [diff] [blame] | 72 | acpi_processor_ppc_has_changed(pr, 1); |
Alexey Starikovskiy | e790cc8 | 2007-11-21 03:23:32 +0300 | [diff] [blame] | 73 | if (saved == pr->performance_platform_limit) |
| 74 | break; |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 75 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 76 | dev_name(&device->dev), event, |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 77 | pr->performance_platform_limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | break; |
| 79 | case ACPI_PROCESSOR_NOTIFY_POWER: |
Sudeep Holla | a36a7fe | 2016-07-21 17:18:07 +0100 | [diff] [blame] | 80 | acpi_processor_power_state_has_changed(pr); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 81 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 82 | dev_name(&device->dev), event, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | break; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 84 | case ACPI_PROCESSOR_NOTIFY_THROTTLING: |
| 85 | acpi_processor_tstate_has_changed(pr); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 86 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 87 | dev_name(&device->dev), event, 0); |
Alan Cox | 879dca0 | 2012-10-26 01:05:56 +0200 | [diff] [blame] | 88 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | default: |
| 90 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 91 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | break; |
| 93 | } |
| 94 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 95 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Paul Gortmaker | fe7bf10 | 2013-06-19 14:30:58 -0400 | [diff] [blame] | 98 | static int __acpi_processor_start(struct acpi_device *device); |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 99 | |
Sebastian Andrzej Siewior | 64f3bf2 | 2016-09-06 19:04:47 +0200 | [diff] [blame] | 100 | static int acpi_soft_cpu_online(unsigned int cpu) |
Venkatesh Pallipadi | 729c6ba | 2007-09-16 15:36:43 +0200 | [diff] [blame] | 101 | { |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 102 | struct acpi_processor *pr = per_cpu(processors, cpu); |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 103 | struct acpi_device *device; |
Toshi Kani | 8da8373 | 2014-05-08 07:58:59 -0600 | [diff] [blame] | 104 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 105 | if (!pr || acpi_bus_get_device(pr->handle, &device)) |
Sebastian Andrzej Siewior | 64f3bf2 | 2016-09-06 19:04:47 +0200 | [diff] [blame] | 106 | return 0; |
| 107 | /* |
| 108 | * CPU got physically hotplugged and onlined for the first time: |
| 109 | * Initialize missing things. |
| 110 | */ |
| 111 | if (pr->flags.need_hotplug_init) { |
| 112 | int ret; |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 113 | |
Sebastian Andrzej Siewior | 64f3bf2 | 2016-09-06 19:04:47 +0200 | [diff] [blame] | 114 | pr_info("Will online and init hotplugged CPU: %d\n", |
| 115 | pr->id); |
| 116 | pr->flags.need_hotplug_init = 0; |
| 117 | ret = __acpi_processor_start(device); |
| 118 | WARN(ret, "Failed to start CPU: %d\n", pr->id); |
| 119 | } else { |
| 120 | /* Normal CPU soft online event. */ |
| 121 | acpi_processor_ppc_has_changed(pr, 0); |
| 122 | acpi_processor_hotplug(pr); |
| 123 | acpi_processor_reevaluate_tstate(pr, false); |
| 124 | acpi_processor_tstate_has_changed(pr); |
Zhao Yakui | 5a344a5 | 2011-01-10 16:35:45 +0800 | [diff] [blame] | 125 | } |
Sebastian Andrzej Siewior | 64f3bf2 | 2016-09-06 19:04:47 +0200 | [diff] [blame] | 126 | return 0; |
Venkatesh Pallipadi | 729c6ba | 2007-09-16 15:36:43 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Sebastian Andrzej Siewior | 64f3bf2 | 2016-09-06 19:04:47 +0200 | [diff] [blame] | 129 | static int acpi_soft_cpu_dead(unsigned int cpu) |
| 130 | { |
| 131 | struct acpi_processor *pr = per_cpu(processors, cpu); |
| 132 | struct acpi_device *device; |
| 133 | |
| 134 | if (!pr || acpi_bus_get_device(pr->handle, &device)) |
| 135 | return 0; |
| 136 | |
| 137 | acpi_processor_reevaluate_tstate(pr, true); |
| 138 | return 0; |
| 139 | } |
Venkatesh Pallipadi | 729c6ba | 2007-09-16 15:36:43 +0200 | [diff] [blame] | 140 | |
Ashwin Chaugule | 239708a | 2015-08-05 09:40:25 -0400 | [diff] [blame] | 141 | #ifdef CONFIG_ACPI_CPU_FREQ_PSS |
| 142 | static int acpi_pss_perf_init(struct acpi_processor *pr, |
| 143 | struct acpi_device *device) |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 144 | { |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 145 | int result = 0; |
| 146 | |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 147 | acpi_processor_ppc_has_changed(pr, 0); |
Ashwin Chaugule | 239708a | 2015-08-05 09:40:25 -0400 | [diff] [blame] | 148 | |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 149 | acpi_processor_get_throttling_info(pr); |
Lan Tianyu | 22e7551 | 2013-08-13 12:11:22 +0200 | [diff] [blame] | 150 | |
| 151 | if (pr->flags.throttling) |
| 152 | pr->flags.limit = 1; |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 153 | |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 154 | pr->cdev = thermal_cooling_device_register("Processor", device, |
| 155 | &processor_cooling_ops); |
| 156 | if (IS_ERR(pr->cdev)) { |
| 157 | result = PTR_ERR(pr->cdev); |
Ashwin Chaugule | 239708a | 2015-08-05 09:40:25 -0400 | [diff] [blame] | 158 | return result; |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | dev_dbg(&device->dev, "registered as cooling_device%d\n", |
| 162 | pr->cdev->id); |
| 163 | |
| 164 | result = sysfs_create_link(&device->dev.kobj, |
| 165 | &pr->cdev->device.kobj, |
| 166 | "thermal_cooling"); |
| 167 | if (result) { |
Toshi Kani | 47db454 | 2012-11-20 23:42:27 +0000 | [diff] [blame] | 168 | dev_err(&device->dev, |
| 169 | "Failed to create sysfs link 'thermal_cooling'\n"); |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 170 | goto err_thermal_unregister; |
| 171 | } |
Ashwin Chaugule | 239708a | 2015-08-05 09:40:25 -0400 | [diff] [blame] | 172 | |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 173 | result = sysfs_create_link(&pr->cdev->device.kobj, |
| 174 | &device->dev.kobj, |
| 175 | "device"); |
| 176 | if (result) { |
Toshi Kani | 47db454 | 2012-11-20 23:42:27 +0000 | [diff] [blame] | 177 | dev_err(&pr->cdev->device, |
| 178 | "Failed to create sysfs link 'device'\n"); |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 179 | goto err_remove_sysfs_thermal; |
| 180 | } |
| 181 | |
Srinivas Pandruvada | ce360db | 2015-12-16 20:32:23 -0800 | [diff] [blame] | 182 | return 0; |
| 183 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 184 | err_remove_sysfs_thermal: |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 185 | sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 186 | err_thermal_unregister: |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 187 | thermal_cooling_device_unregister(pr->cdev); |
Ashwin Chaugule | 239708a | 2015-08-05 09:40:25 -0400 | [diff] [blame] | 188 | |
| 189 | return result; |
| 190 | } |
| 191 | |
| 192 | static void acpi_pss_perf_exit(struct acpi_processor *pr, |
| 193 | struct acpi_device *device) |
| 194 | { |
| 195 | if (pr->cdev) { |
| 196 | sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); |
| 197 | sysfs_remove_link(&pr->cdev->device.kobj, "device"); |
| 198 | thermal_cooling_device_unregister(pr->cdev); |
| 199 | pr->cdev = NULL; |
| 200 | } |
| 201 | } |
| 202 | #else |
| 203 | static inline int acpi_pss_perf_init(struct acpi_processor *pr, |
| 204 | struct acpi_device *device) |
| 205 | { |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static inline void acpi_pss_perf_exit(struct acpi_processor *pr, |
| 210 | struct acpi_device *device) {} |
| 211 | #endif /* CONFIG_ACPI_CPU_FREQ_PSS */ |
| 212 | |
| 213 | static int __acpi_processor_start(struct acpi_device *device) |
| 214 | { |
| 215 | struct acpi_processor *pr = acpi_driver_data(device); |
| 216 | acpi_status status; |
| 217 | int result = 0; |
| 218 | |
| 219 | if (!pr) |
| 220 | return -ENODEV; |
| 221 | |
| 222 | if (pr->flags.need_hotplug_init) |
| 223 | return 0; |
| 224 | |
Ashwin Chaugule | 4f2f757 | 2015-09-09 16:27:07 -0400 | [diff] [blame] | 225 | result = acpi_cppc_processor_probe(pr); |
Srinivas Pandruvada | 65e9589 | 2016-09-01 13:37:08 -0700 | [diff] [blame] | 226 | if (result && !IS_ENABLED(CONFIG_ACPI_CPU_FREQ_PSS)) |
Hanjun Guo | 512bb03 | 2017-07-26 18:40:12 +0800 | [diff] [blame] | 227 | dev_dbg(&device->dev, "CPPC data invalid or not present\n"); |
Ashwin Chaugule | 4f2f757 | 2015-09-09 16:27:07 -0400 | [diff] [blame] | 228 | |
Ashwin Chaugule | 239708a | 2015-08-05 09:40:25 -0400 | [diff] [blame] | 229 | if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver) |
| 230 | acpi_processor_power_init(pr); |
| 231 | |
| 232 | result = acpi_pss_perf_init(pr, device); |
| 233 | if (result) |
| 234 | goto err_power_exit; |
| 235 | |
| 236 | status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, |
| 237 | acpi_processor_notify, device); |
| 238 | if (ACPI_SUCCESS(status)) |
| 239 | return 0; |
| 240 | |
Thomas Gleixner | a5cbdf6 | 2017-04-12 22:07:33 +0200 | [diff] [blame] | 241 | result = -ENODEV; |
| 242 | acpi_pss_perf_exit(pr, device); |
| 243 | |
Ashwin Chaugule | 239708a | 2015-08-05 09:40:25 -0400 | [diff] [blame] | 244 | err_power_exit: |
Daniel Lezcano | 38a991b | 2012-09-15 22:42:54 +0200 | [diff] [blame] | 245 | acpi_processor_power_exit(pr); |
Thomas Renninger | 54d5dcc | 2012-01-19 18:18:42 +0100 | [diff] [blame] | 246 | return result; |
| 247 | } |
| 248 | |
Paul Gortmaker | fe7bf10 | 2013-06-19 14:30:58 -0400 | [diff] [blame] | 249 | static int acpi_processor_start(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
Lan Tianyu | d0a7edb | 2013-12-06 15:36:26 +0800 | [diff] [blame] | 251 | struct acpi_device *device = ACPI_COMPANION(dev); |
Thomas Gleixner | 8153f9a | 2017-04-12 22:07:34 +0200 | [diff] [blame] | 252 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Lan Tianyu | d0a7edb | 2013-12-06 15:36:26 +0800 | [diff] [blame] | 254 | if (!device) |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 255 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Thomas Gleixner | 8153f9a | 2017-04-12 22:07:34 +0200 | [diff] [blame] | 257 | /* Protect against concurrent CPU hotplug operations */ |
Thomas Gleixner | fdaf0a5 | 2017-05-24 10:15:33 +0200 | [diff] [blame] | 258 | cpu_hotplug_disable(); |
Thomas Gleixner | 8153f9a | 2017-04-12 22:07:34 +0200 | [diff] [blame] | 259 | ret = __acpi_processor_start(device); |
Thomas Gleixner | fdaf0a5 | 2017-05-24 10:15:33 +0200 | [diff] [blame] | 260 | cpu_hotplug_enable(); |
Thomas Gleixner | 8153f9a | 2017-04-12 22:07:34 +0200 | [diff] [blame] | 261 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 264 | static int acpi_processor_stop(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
Lan Tianyu | d0a7edb | 2013-12-06 15:36:26 +0800 | [diff] [blame] | 266 | struct acpi_device *device = ACPI_COMPANION(dev); |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 267 | struct acpi_processor *pr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Lan Tianyu | d0a7edb | 2013-12-06 15:36:26 +0800 | [diff] [blame] | 269 | if (!device) |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 270 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 272 | acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, |
| 273 | acpi_processor_notify); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 275 | pr = acpi_driver_data(device); |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 276 | if (!pr) |
| 277 | return 0; |
Daniel Lezcano | 38a991b | 2012-09-15 22:42:54 +0200 | [diff] [blame] | 278 | acpi_processor_power_exit(pr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Ashwin Chaugule | 239708a | 2015-08-05 09:40:25 -0400 | [diff] [blame] | 280 | acpi_pss_perf_exit(pr, device); |
| 281 | |
Ashwin Chaugule | 4f2f757 | 2015-09-09 16:27:07 -0400 | [diff] [blame] | 282 | acpi_cppc_processor_exit(pr); |
| 283 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 284 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Viresh Kumar | d15ce41 | 2019-08-28 14:20:13 +0530 | [diff] [blame] | 287 | bool acpi_processor_cpufreq_init; |
| 288 | |
| 289 | static int acpi_processor_notifier(struct notifier_block *nb, |
| 290 | unsigned long event, void *data) |
| 291 | { |
| 292 | struct cpufreq_policy *policy = data; |
Viresh Kumar | d15ce41 | 2019-08-28 14:20:13 +0530 | [diff] [blame] | 293 | |
| 294 | if (event == CPUFREQ_CREATE_POLICY) { |
Rafael J. Wysocki | 3000ce3 | 2019-10-16 12:47:06 +0200 | [diff] [blame] | 295 | acpi_thermal_cpufreq_init(policy); |
| 296 | acpi_processor_ppc_init(policy); |
Viresh Kumar | d15ce41 | 2019-08-28 14:20:13 +0530 | [diff] [blame] | 297 | } else if (event == CPUFREQ_REMOVE_POLICY) { |
Rafael J. Wysocki | 3000ce3 | 2019-10-16 12:47:06 +0200 | [diff] [blame] | 298 | acpi_processor_ppc_exit(policy); |
| 299 | acpi_thermal_cpufreq_exit(policy); |
Viresh Kumar | d15ce41 | 2019-08-28 14:20:13 +0530 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | static struct notifier_block acpi_processor_notifier_block = { |
| 306 | .notifier_call = acpi_processor_notifier, |
| 307 | }; |
| 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | /* |
| 310 | * We keep the driver loaded even when ACPI is not running. |
| 311 | * This is needed for the powernow-k8 driver, that works even without |
| 312 | * ACPI, but needs symbols from this driver |
| 313 | */ |
Sebastian Andrzej Siewior | 64f3bf2 | 2016-09-06 19:04:47 +0200 | [diff] [blame] | 314 | static enum cpuhp_state hp_online; |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 315 | static int __init acpi_processor_driver_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Yinghai Lu | ce8442b | 2009-08-26 14:29:26 -0700 | [diff] [blame] | 319 | if (acpi_disabled) |
| 320 | return 0; |
| 321 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 322 | result = driver_register(&acpi_processor_driver); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 323 | if (result < 0) |
Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 324 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Sebastian Andrzej Siewior | 64f3bf2 | 2016-09-06 19:04:47 +0200 | [diff] [blame] | 326 | result = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, |
| 327 | "acpi/cpu-drv:online", |
| 328 | acpi_soft_cpu_online, NULL); |
| 329 | if (result < 0) |
| 330 | goto err; |
| 331 | hp_online = result; |
| 332 | cpuhp_setup_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD, "acpi/cpu-drv:dead", |
| 333 | NULL, acpi_soft_cpu_dead); |
| 334 | |
Viresh Kumar | d15ce41 | 2019-08-28 14:20:13 +0530 | [diff] [blame] | 335 | if (!cpufreq_register_notifier(&acpi_processor_notifier_block, |
| 336 | CPUFREQ_POLICY_NOTIFIER)) { |
| 337 | acpi_processor_cpufreq_init = true; |
| 338 | acpi_processor_ignore_ppc_init(); |
| 339 | } |
| 340 | |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 341 | acpi_processor_throttling_init(); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 342 | return 0; |
Sebastian Andrzej Siewior | 64f3bf2 | 2016-09-06 19:04:47 +0200 | [diff] [blame] | 343 | err: |
| 344 | driver_unregister(&acpi_processor_driver); |
| 345 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 348 | static void __exit acpi_processor_driver_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
Yinghai Lu | ce8442b | 2009-08-26 14:29:26 -0700 | [diff] [blame] | 350 | if (acpi_disabled) |
| 351 | return; |
| 352 | |
Viresh Kumar | d15ce41 | 2019-08-28 14:20:13 +0530 | [diff] [blame] | 353 | if (acpi_processor_cpufreq_init) { |
| 354 | cpufreq_unregister_notifier(&acpi_processor_notifier_block, |
| 355 | CPUFREQ_POLICY_NOTIFIER); |
| 356 | acpi_processor_cpufreq_init = false; |
| 357 | } |
| 358 | |
Sebastian Andrzej Siewior | 64f3bf2 | 2016-09-06 19:04:47 +0200 | [diff] [blame] | 359 | cpuhp_remove_state_nocalls(hp_online); |
| 360 | cpuhp_remove_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD); |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 361 | driver_unregister(&acpi_processor_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Rafael J. Wysocki | ac212b6 | 2013-05-03 00:26:22 +0200 | [diff] [blame] | 364 | module_init(acpi_processor_driver_init); |
| 365 | module_exit(acpi_processor_driver_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | MODULE_ALIAS("processor"); |