29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
33 #include <linux/sched.h>
37 #include <asm/uaccess.h>
43 #define PREFIX "ACPI: "
45 #define ACPI_PROCESSOR_CLASS "processor"
46 #define _COMPONENT ACPI_PROCESSOR_COMPONENT
53 static int ignore_tpc;
62 #define THROTTLING_PRECHANGE (1)
63 #define THROTTLING_POSTCHANGE (2)
69 static int acpi_processor_update_tsd_coord(
void)
71 int count, count_target;
79 if (!zalloc_cpumask_var(&covered_cpus,
GFP_KERNEL))
118 cpumask_set_cpu(i, covered_cpus);
134 match_pr =
per_cpu(processors, j);
159 cpumask_set_cpu(j, covered_cpus);
167 match_pr =
per_cpu(processors, j);
186 free_cpumask_var(covered_cpus);
214 if (acpi_processor_update_tsd_coord())
216 "Assume no T-state coordination\n"));
221 static int acpi_processor_throttling_notifier(
unsigned long event,
void *
data)
236 if (!pr->
flags.throttling) {
238 "unsupported on CPU %d\n", cpu));
249 p_limit = &pr->
limit;
250 if (p_limit->
thermal.tx > target_state)
251 target_state = p_limit->
thermal.tx;
252 if (p_limit->
user.tx > target_state)
253 target_state = p_limit->
user.tx;
258 "Exceed the limit of T-state \n");
263 "target T-state of CPU %d is T%d\n",
271 p_throttling->
state = target_state;
273 "CPU %d is switched to T%d\n",
278 "Unsupported Throttling notifier event\n");
288 static int acpi_processor_get_platform_limit(
struct acpi_processor *pr)
291 unsigned long long tpc = 0;
315 int throttling_limit;
323 result = acpi_processor_get_platform_limit(pr);
330 if (throttling_limit >= pr->
throttling.state_count) {
336 if (current_state > throttling_limit) {
345 target_state = throttling_limit;
346 if (limit->
thermal.tx > target_state)
347 target_state = limit->
thermal.tx;
348 if (limit->
user.tx > target_state)
349 target_state = limit->
user.tx;
350 }
else if (current_state == throttling_limit) {
363 target_state = throttling_limit;
386 pr->
flags.throttling = 0;
396 pr->
flags.throttling = 0;
399 pr->
flags.throttling = 1;
406 result = acpi_processor_get_throttling(pr);
418 pr->
flags.throttling = 0;
423 static int acpi_processor_get_throttling_control(
struct acpi_processor *pr)
442 || (ptc->
package.count != 2)) {
452 obj = ptc->
package.elements[0];
458 "Invalid _PTC data (control_register)\n");
469 obj = ptc->
package.elements[1];
507 static int acpi_processor_get_throttling_states(
struct acpi_processor *pr)
544 for (i = 0; i < pr->
throttling.state_count; i++) {
566 "Invalid _TSS data: freq is zero\n");
587 struct acpi_buffer format = {
sizeof(
"NNNNN"),
"NNNNN" };
666 static int acpi_processor_get_throttling_fadt(
struct acpi_processor *pr)
676 if (!pr->
flags.throttling)
694 duty_value = value & duty_mask;
698 state = pr->
throttling.state_count - duty_value;
706 "Throttling state is T%d (%d%% throttling applied)\n",
707 state, pr->
throttling.states[state].performance));
713 static int acpi_throttling_rdmsr(
u64 *value)
715 u64 msr_high, msr_low;
722 "HARDWARE addr space,NOT supported yet\n");
727 (
u32 *)&msr_low , (
u32 *) &msr_high);
728 msr = (msr_high << 32) | msr_low;
735 static int acpi_throttling_wrmsr(
u64 value)
743 "HARDWARE addr space,NOT supported yet\n");
747 msr & 0xffffffff, msr >> 32);
753 static int acpi_throttling_rdmsr(
u64 *value)
756 "HARDWARE addr space,NOT supported yet\n");
760 static int acpi_throttling_wrmsr(
u64 value)
763 "HARDWARE addr space,NOT supported yet\n");
785 (
u32) (bit_width + bit_offset));
787 *value = (
u64) ((ptc_value >> bit_offset) & ptc_mask);
791 ret = acpi_throttling_rdmsr(value);
815 ptc_value = value & ptc_mask;
819 (
u32) (ptc_value << bit_offset),
820 (
u32) (bit_width + bit_offset));
824 ret = acpi_throttling_wrmsr(value);
838 for (i = 0; i < pr->
throttling.state_count; i++) {
849 int state,
u64 *value)
863 static int acpi_processor_get_throttling_ptc(
struct acpi_processor *pr)
872 if (!pr->
flags.throttling)
878 ret = acpi_read_throttling_status(pr, &value);
880 state = acpi_get_throttling_state(pr, value);
883 "Invalid throttling state, reset\n"));
895 static int acpi_processor_get_throttling(
struct acpi_processor *pr)
903 if (!pr->
flags.throttling)
906 if (!alloc_cpumask_var(&saved_mask,
GFP_KERNEL))
912 cpumask_copy(saved_mask, &
current->cpus_allowed);
916 free_cpumask_var(saved_mask);
919 ret = pr->
throttling.acpi_processor_get_throttling(pr);
921 set_cpus_allowed_ptr(
current, saved_mask);
922 free_cpumask_var(saved_mask);
927 static int acpi_processor_get_fadt_info(
struct acpi_processor *pr)
954 for (i = 0; i < pr->
throttling.state_count; i++) {
961 static int acpi_processor_set_throttling_fadt(
struct acpi_processor *pr,
962 int state,
bool force)
971 if ((state < 0) || (state > (pr->
throttling.state_count - 1)))
974 if (!pr->
flags.throttling)
977 if (!force && (state == pr->
throttling.state))
994 duty_mask = ~duty_mask;
1005 value &= 0xFFFFFFEF;
1015 value |= duty_value;
1018 value |= 0x00000010;
1027 "Throttling state set to T%d (%d%%)\n", state,
1028 (pr->
throttling.states[state].performance ? pr->
1029 throttling.
states[state].performance / 10 : 0)));
1034 static int acpi_processor_set_throttling_ptc(
struct acpi_processor *pr,
1035 int state,
bool force)
1043 if ((state < 0) || (state > (pr->
throttling.state_count - 1)))
1046 if (!pr->
flags.throttling)
1049 if (!force && (state == pr->
throttling.state))
1056 ret = acpi_get_throttling_value(pr, state, &value);
1058 acpi_write_throttling_state(pr, value);
1066 int state,
bool force)
1079 if (!pr->
flags.throttling)
1082 if ((state < 0) || (state > (pr->
throttling.state_count - 1)))
1085 if (!alloc_cpumask_var(&saved_mask,
GFP_KERNEL))
1088 if (!alloc_cpumask_var(&online_throttling_cpus,
GFP_KERNEL)) {
1089 free_cpumask_var(saved_mask);
1101 cpumask_copy(saved_mask, &
current->cpus_allowed);
1138 match_pr =
per_cpu(processors, i);
1145 "Invalid Pointer for CPU %d\n", i));
1152 if (!match_pr->
flags.throttling) {
1154 "Throttling Control is unsupported "
1180 set_cpus_allowed_ptr(
current, saved_mask);
1182 free_cpumask_var(online_throttling_cpus);
1183 free_cpumask_var(saved_mask);
1193 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
1202 if (acpi_processor_get_throttling_control(pr) ||
1203 acpi_processor_get_throttling_states(pr) ||
1204 acpi_processor_get_platform_limit(pr))
1206 pr->
throttling.acpi_processor_get_throttling =
1207 &acpi_processor_get_throttling_fadt;
1208 pr->
throttling.acpi_processor_set_throttling =
1209 &acpi_processor_set_throttling_fadt;
1210 if (acpi_processor_get_fadt_info(pr))
1213 pr->
throttling.acpi_processor_get_throttling =
1214 &acpi_processor_get_throttling_ptc;
1215 pr->
throttling.acpi_processor_set_throttling =
1216 &acpi_processor_set_throttling_ptc;
1223 if (acpi_processor_get_tsd(pr)) {
1235 if (
errata.piix4.throttle) {
1237 "Throttling not supported on PIIX4 A- or B-step\n"));
1244 pr->
flags.throttling = 1;
1258 "Disabling throttling (was T%d)\n",
1267 pr->
flags.throttling = 0;