Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 2 | /* |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 3 | * This file provides the ACPI based P-state support. This |
| 4 | * module works with generic cpufreq infrastructure. Most of |
| 5 | * the code is based on i386 version |
| 6 | * (arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c) |
| 7 | * |
| 8 | * Copyright (C) 2005 Intel Corp |
| 9 | * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> |
| 10 | */ |
| 11 | |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 16 | #include <linux/module.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/cpufreq.h> |
| 19 | #include <linux/proc_fs.h> |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 20 | #include <asm/io.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 21 | #include <linux/uaccess.h> |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 22 | #include <asm/pal.h> |
| 23 | |
| 24 | #include <linux/acpi.h> |
| 25 | #include <acpi/processor.h> |
| 26 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 27 | MODULE_AUTHOR("Venkatesh Pallipadi"); |
| 28 | MODULE_DESCRIPTION("ACPI Processor P-States Driver"); |
| 29 | MODULE_LICENSE("GPL"); |
| 30 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 31 | struct cpufreq_acpi_io { |
| 32 | struct acpi_processor_performance acpi_data; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 33 | unsigned int resume; |
| 34 | }; |
| 35 | |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 36 | struct cpufreq_acpi_req { |
| 37 | unsigned int cpu; |
| 38 | unsigned int state; |
| 39 | }; |
| 40 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 41 | static struct cpufreq_acpi_io *acpi_io_data[NR_CPUS]; |
| 42 | |
| 43 | static struct cpufreq_driver acpi_cpufreq_driver; |
| 44 | |
| 45 | |
| 46 | static int |
| 47 | processor_set_pstate ( |
| 48 | u32 value) |
| 49 | { |
| 50 | s64 retval; |
| 51 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 52 | pr_debug("processor_set_pstate\n"); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 53 | |
| 54 | retval = ia64_pal_set_pstate((u64)value); |
| 55 | |
| 56 | if (retval) { |
Sergei Trofimovich | 4c56f57 | 2021-03-13 10:42:14 +0000 | [diff] [blame] | 57 | pr_debug("Failed to set freq to 0x%x, with error 0x%llx\n", |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 58 | value, retval); |
| 59 | return -ENODEV; |
| 60 | } |
| 61 | return (int)retval; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | static int |
| 66 | processor_get_pstate ( |
| 67 | u32 *value) |
| 68 | { |
| 69 | u64 pstate_index = 0; |
| 70 | s64 retval; |
| 71 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 72 | pr_debug("processor_get_pstate\n"); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 73 | |
Venkatesh Pallipadi | 17e77b1 | 2006-12-01 15:28:14 -0800 | [diff] [blame] | 74 | retval = ia64_pal_get_pstate(&pstate_index, |
| 75 | PAL_GET_PSTATE_TYPE_INSTANT); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 76 | *value = (u32) pstate_index; |
| 77 | |
| 78 | if (retval) |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 79 | pr_debug("Failed to get current freq with " |
Sergei Trofimovich | 4c56f57 | 2021-03-13 10:42:14 +0000 | [diff] [blame] | 80 | "error 0x%llx, idx 0x%x\n", retval, *value); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 81 | |
| 82 | return (int)retval; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | /* To be used only after data->acpi_data is initialized */ |
| 87 | static unsigned |
| 88 | extract_clock ( |
| 89 | struct cpufreq_acpi_io *data, |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 90 | unsigned value) |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 91 | { |
| 92 | unsigned long i; |
| 93 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 94 | pr_debug("extract_clock\n"); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 95 | |
| 96 | for (i = 0; i < data->acpi_data.state_count; i++) { |
Venkatesh Pallipadi | 17e77b1 | 2006-12-01 15:28:14 -0800 | [diff] [blame] | 97 | if (value == data->acpi_data.states[i].status) |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 98 | return data->acpi_data.states[i].core_frequency; |
| 99 | } |
| 100 | return data->acpi_data.states[i-1].core_frequency; |
| 101 | } |
| 102 | |
| 103 | |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 104 | static long |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 105 | processor_get_freq ( |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 106 | void *arg) |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 107 | { |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 108 | struct cpufreq_acpi_req *req = arg; |
| 109 | unsigned int cpu = req->cpu; |
| 110 | struct cpufreq_acpi_io *data = acpi_io_data[cpu]; |
| 111 | u32 value; |
| 112 | int ret; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 113 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 114 | pr_debug("processor_get_freq\n"); |
Alex Williamson | 182fdd2 | 2007-08-13 15:49:46 -0600 | [diff] [blame] | 115 | if (smp_processor_id() != cpu) |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 116 | return -EAGAIN; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 117 | |
Venkatesh Pallipadi | 17e77b1 | 2006-12-01 15:28:14 -0800 | [diff] [blame] | 118 | /* processor_get_pstate gets the instantaneous frequency */ |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 119 | ret = processor_get_pstate(&value); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 120 | if (ret) { |
Joe Perches | b49c22a | 2016-04-05 13:28:24 -0700 | [diff] [blame] | 121 | pr_warn("get performance failed with error %d\n", ret); |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 122 | return ret; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 123 | } |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 124 | return 1000 * extract_clock(data, value); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 128 | static long |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 129 | processor_set_freq ( |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 130 | void *arg) |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 131 | { |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 132 | struct cpufreq_acpi_req *req = arg; |
| 133 | unsigned int cpu = req->cpu; |
| 134 | struct cpufreq_acpi_io *data = acpi_io_data[cpu]; |
| 135 | int ret, state = req->state; |
| 136 | u32 value; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 137 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 138 | pr_debug("processor_set_freq\n"); |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 139 | if (smp_processor_id() != cpu) |
| 140 | return -EAGAIN; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 141 | |
| 142 | if (state == data->acpi_data.state) { |
| 143 | if (unlikely(data->resume)) { |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 144 | pr_debug("Called after resume, resetting to P%d\n", state); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 145 | data->resume = 0; |
| 146 | } else { |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 147 | pr_debug("Already at target state (P%d)\n", state); |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 148 | return 0; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 152 | pr_debug("Transitioning from P%d to P%d\n", |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 153 | data->acpi_data.state, state); |
| 154 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 155 | /* |
| 156 | * First we write the target state's 'control' value to the |
| 157 | * control_register. |
| 158 | */ |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 159 | value = (u32) data->acpi_data.states[state].control; |
| 160 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 161 | pr_debug("Transitioning to state: 0x%08x\n", value); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 162 | |
| 163 | ret = processor_set_pstate(value); |
| 164 | if (ret) { |
Joe Perches | b49c22a | 2016-04-05 13:28:24 -0700 | [diff] [blame] | 165 | pr_warn("Transition failed with error %d\n", ret); |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 166 | return -ENODEV; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 169 | data->acpi_data.state = state; |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 170 | return 0; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | |
| 174 | static unsigned int |
| 175 | acpi_cpufreq_get ( |
| 176 | unsigned int cpu) |
| 177 | { |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 178 | struct cpufreq_acpi_req req; |
| 179 | long ret; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 180 | |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 181 | req.cpu = cpu; |
| 182 | ret = work_on_cpu(cpu, processor_get_freq, &req); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 183 | |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 184 | return ret > 0 ? (unsigned int) ret : 0; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
| 188 | static int |
| 189 | acpi_cpufreq_target ( |
| 190 | struct cpufreq_policy *policy, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 191 | unsigned int index) |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 192 | { |
Thomas Gleixner | 38f05ed | 2017-04-12 22:55:03 +0200 | [diff] [blame] | 193 | struct cpufreq_acpi_req req; |
| 194 | |
| 195 | req.cpu = policy->cpu; |
| 196 | req.state = index; |
| 197 | |
| 198 | return work_on_cpu(req.cpu, processor_set_freq, &req); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 201 | static int |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 202 | acpi_cpufreq_cpu_init ( |
| 203 | struct cpufreq_policy *policy) |
| 204 | { |
| 205 | unsigned int i; |
| 206 | unsigned int cpu = policy->cpu; |
| 207 | struct cpufreq_acpi_io *data; |
| 208 | unsigned int result = 0; |
Pan Xinhui | 946c14f | 2015-07-20 14:22:46 +0800 | [diff] [blame] | 209 | struct cpufreq_frequency_table *freq_table; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 210 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 211 | pr_debug("acpi_cpufreq_cpu_init\n"); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 212 | |
Viresh Kumar | d5b73cd | 2013-08-06 22:53:06 +0530 | [diff] [blame] | 213 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 214 | if (!data) |
| 215 | return (-ENOMEM); |
| 216 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 217 | acpi_io_data[cpu] = data; |
| 218 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 219 | result = acpi_processor_register_performance(&data->acpi_data, cpu); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 220 | |
| 221 | if (result) |
| 222 | goto err_free; |
| 223 | |
| 224 | /* capability check */ |
| 225 | if (data->acpi_data.state_count <= 1) { |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 226 | pr_debug("No P-States\n"); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 227 | result = -ENODEV; |
| 228 | goto err_unreg; |
| 229 | } |
| 230 | |
| 231 | if ((data->acpi_data.control_register.space_id != |
| 232 | ACPI_ADR_SPACE_FIXED_HARDWARE) || |
| 233 | (data->acpi_data.status_register.space_id != |
| 234 | ACPI_ADR_SPACE_FIXED_HARDWARE)) { |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 235 | pr_debug("Unsupported address space [%d, %d]\n", |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 236 | (u32) (data->acpi_data.control_register.space_id), |
| 237 | (u32) (data->acpi_data.status_register.space_id)); |
| 238 | result = -ENODEV; |
| 239 | goto err_unreg; |
| 240 | } |
| 241 | |
| 242 | /* alloc freq_table */ |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 243 | freq_table = kcalloc(data->acpi_data.state_count + 1, |
| 244 | sizeof(*freq_table), |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 245 | GFP_KERNEL); |
Pan Xinhui | 946c14f | 2015-07-20 14:22:46 +0800 | [diff] [blame] | 246 | if (!freq_table) { |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 247 | result = -ENOMEM; |
| 248 | goto err_unreg; |
| 249 | } |
| 250 | |
| 251 | /* detect transition latency */ |
| 252 | policy->cpuinfo.transition_latency = 0; |
| 253 | for (i=0; i<data->acpi_data.state_count; i++) { |
| 254 | if ((data->acpi_data.states[i].transition_latency * 1000) > |
| 255 | policy->cpuinfo.transition_latency) { |
| 256 | policy->cpuinfo.transition_latency = |
| 257 | data->acpi_data.states[i].transition_latency * 1000; |
| 258 | } |
| 259 | } |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 260 | |
| 261 | /* table init */ |
| 262 | for (i = 0; i <= data->acpi_data.state_count; i++) |
| 263 | { |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 264 | if (i < data->acpi_data.state_count) { |
Pan Xinhui | 946c14f | 2015-07-20 14:22:46 +0800 | [diff] [blame] | 265 | freq_table[i].frequency = |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 266 | data->acpi_data.states[i].core_frequency * 1000; |
| 267 | } else { |
Pan Xinhui | 946c14f | 2015-07-20 14:22:46 +0800 | [diff] [blame] | 268 | freq_table[i].frequency = CPUFREQ_TABLE_END; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
Viresh Kumar | b666362 | 2018-02-26 10:38:53 +0530 | [diff] [blame] | 272 | policy->freq_table = freq_table; |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 273 | |
| 274 | /* notify BIOS that we exist */ |
| 275 | acpi_processor_notify_smm(THIS_MODULE); |
| 276 | |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 277 | pr_info("CPU%u - ACPI performance management activated\n", cpu); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 278 | |
| 279 | for (i = 0; i < data->acpi_data.state_count; i++) |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 280 | pr_debug(" %cP%d: %d MHz, %d mW, %d uS, %d uS, 0x%x 0x%x\n", |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 281 | (i == data->acpi_data.state?'*':' '), i, |
| 282 | (u32) data->acpi_data.states[i].core_frequency, |
| 283 | (u32) data->acpi_data.states[i].power, |
| 284 | (u32) data->acpi_data.states[i].transition_latency, |
| 285 | (u32) data->acpi_data.states[i].bus_master_latency, |
| 286 | (u32) data->acpi_data.states[i].status, |
| 287 | (u32) data->acpi_data.states[i].control); |
| 288 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 289 | /* the first call to ->target() should result in us actually |
| 290 | * writing something to the appropriate registers. */ |
| 291 | data->resume = 1; |
| 292 | |
| 293 | return (result); |
| 294 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 295 | err_unreg: |
Rafael J. Wysocki | b2f8dc4 | 2015-07-22 22:11:16 +0200 | [diff] [blame] | 296 | acpi_processor_unregister_performance(cpu); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 297 | err_free: |
| 298 | kfree(data); |
| 299 | acpi_io_data[cpu] = NULL; |
| 300 | |
| 301 | return (result); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | static int |
| 306 | acpi_cpufreq_cpu_exit ( |
| 307 | struct cpufreq_policy *policy) |
| 308 | { |
| 309 | struct cpufreq_acpi_io *data = acpi_io_data[policy->cpu]; |
| 310 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 311 | pr_debug("acpi_cpufreq_cpu_exit\n"); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 312 | |
| 313 | if (data) { |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 314 | acpi_io_data[policy->cpu] = NULL; |
Rafael J. Wysocki | b2f8dc4 | 2015-07-22 22:11:16 +0200 | [diff] [blame] | 315 | acpi_processor_unregister_performance(policy->cpu); |
Pan Xinhui | 555f3fe | 2015-07-20 14:24:36 +0800 | [diff] [blame] | 316 | kfree(policy->freq_table); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 317 | kfree(data); |
| 318 | } |
| 319 | |
| 320 | return (0); |
| 321 | } |
| 322 | |
| 323 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 324 | static struct cpufreq_driver acpi_cpufreq_driver = { |
Viresh Kumar | 59b2413 | 2013-10-03 20:28:07 +0530 | [diff] [blame] | 325 | .verify = cpufreq_generic_frequency_table_verify, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 326 | .target_index = acpi_cpufreq_target, |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 327 | .get = acpi_cpufreq_get, |
| 328 | .init = acpi_cpufreq_cpu_init, |
| 329 | .exit = acpi_cpufreq_cpu_exit, |
| 330 | .name = "acpi-cpufreq", |
Viresh Kumar | 59b2413 | 2013-10-03 20:28:07 +0530 | [diff] [blame] | 331 | .attr = cpufreq_generic_attr, |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 332 | }; |
| 333 | |
| 334 | |
| 335 | static int __init |
| 336 | acpi_cpufreq_init (void) |
| 337 | { |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 338 | pr_debug("acpi_cpufreq_init\n"); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 339 | |
| 340 | return cpufreq_register_driver(&acpi_cpufreq_driver); |
| 341 | } |
| 342 | |
| 343 | |
| 344 | static void __exit |
| 345 | acpi_cpufreq_exit (void) |
| 346 | { |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 347 | pr_debug("acpi_cpufreq_exit\n"); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 348 | |
| 349 | cpufreq_unregister_driver(&acpi_cpufreq_driver); |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Venkatesh Pallipadi | 4db8699 | 2005-07-29 16:15:00 -0700 | [diff] [blame] | 352 | late_initcall(acpi_cpufreq_init); |
| 353 | module_exit(acpi_cpufreq_exit); |