1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * processor_throttling.c - Throttling submodule of the ACPI processor driver
9 * - Added processor hotplug support
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/init.h>
16 #include <linux/sched.h>
17 #include <linux/cpufreq.h>
18 #include <linux/acpi.h>
19 #include <acpi/processor.h>
21 #include <linux/uaccess.h>
23 #define PREFIX "ACPI: "
25 #define _COMPONENT ACPI_PROCESSOR_COMPONENT
26 ACPI_MODULE_NAME("processor_throttling");
29 * 0 -> acpi processor driver doesn't ignore _TPC values
30 * 1 -> acpi processor driver ignores _TPC values
32 static int ignore_tpc;
33 module_param(ignore_tpc, int, 0644);
34 MODULE_PARM_DESC(ignore_tpc, "Disable broken BIOS _TPC throttling support");
36 struct throttling_tstate {
37 unsigned int cpu; /* cpu nr */
38 int target_state; /* target T-state */
41 struct acpi_processor_throttling_arg {
42 struct acpi_processor *pr;
47 #define THROTTLING_PRECHANGE (1)
48 #define THROTTLING_POSTCHANGE (2)
50 static int acpi_processor_get_throttling(struct acpi_processor *pr);
51 static int __acpi_processor_set_throttling(struct acpi_processor *pr,
52 int state, bool force, bool direct);
54 static int acpi_processor_update_tsd_coord(void)
56 int count, count_target;
59 cpumask_var_t covered_cpus;
60 struct acpi_processor *pr, *match_pr;
61 struct acpi_tsd_package *pdomain, *match_pdomain;
62 struct acpi_processor_throttling *pthrottling, *match_pthrottling;
64 if (!zalloc_cpumask_var(&covered_cpus, GFP_KERNEL))
68 * Now that we have _TSD data from all CPUs, lets setup T-state
69 * coordination between all CPUs.
71 for_each_possible_cpu(i) {
72 pr = per_cpu(processors, i);
76 /* Basic validity check for domain info */
77 pthrottling = &(pr->throttling);
80 * If tsd package for one cpu is invalid, the coordination
81 * among all CPUs is thought as invalid.
84 if (!pthrottling->tsd_valid_flag) {
92 for_each_possible_cpu(i) {
93 pr = per_cpu(processors, i);
97 if (cpumask_test_cpu(i, covered_cpus))
99 pthrottling = &pr->throttling;
101 pdomain = &(pthrottling->domain_info);
102 cpumask_set_cpu(i, pthrottling->shared_cpu_map);
103 cpumask_set_cpu(i, covered_cpus);
105 * If the number of processor in the TSD domain is 1, it is
106 * unnecessary to parse the coordination for this CPU.
108 if (pdomain->num_processors <= 1)
111 /* Validate the Domain info */
112 count_target = pdomain->num_processors;
115 for_each_possible_cpu(j) {
119 match_pr = per_cpu(processors, j);
123 match_pthrottling = &(match_pr->throttling);
124 match_pdomain = &(match_pthrottling->domain_info);
125 if (match_pdomain->domain != pdomain->domain)
128 /* Here i and j are in the same domain.
129 * If two TSD packages have the same domain, they
130 * should have the same num_porcessors and
131 * coordination type. Otherwise it will be regarded
134 if (match_pdomain->num_processors != count_target) {
139 if (pdomain->coord_type != match_pdomain->coord_type) {
144 cpumask_set_cpu(j, covered_cpus);
145 cpumask_set_cpu(j, pthrottling->shared_cpu_map);
148 for_each_possible_cpu(j) {
152 match_pr = per_cpu(processors, j);
156 match_pthrottling = &(match_pr->throttling);
157 match_pdomain = &(match_pthrottling->domain_info);
158 if (match_pdomain->domain != pdomain->domain)
162 * If some CPUS have the same domain, they
163 * will have the same shared_cpu_map.
165 cpumask_copy(match_pthrottling->shared_cpu_map,
166 pthrottling->shared_cpu_map);
171 free_cpumask_var(covered_cpus);
173 for_each_possible_cpu(i) {
174 pr = per_cpu(processors, i);
179 * Assume no coordination on any error parsing domain info.
180 * The coordination type will be forced as SW_ALL.
183 pthrottling = &(pr->throttling);
184 cpumask_clear(pthrottling->shared_cpu_map);
185 cpumask_set_cpu(i, pthrottling->shared_cpu_map);
186 pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL;
194 * Update the T-state coordination after the _TSD
195 * data for all cpus is obtained.
197 void acpi_processor_throttling_init(void)
199 if (acpi_processor_update_tsd_coord()) {
200 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
201 "Assume no T-state coordination\n"));
207 static int acpi_processor_throttling_notifier(unsigned long event, void *data)
209 struct throttling_tstate *p_tstate = data;
210 struct acpi_processor *pr;
213 struct acpi_processor_limit *p_limit;
214 struct acpi_processor_throttling *p_throttling;
217 pr = per_cpu(processors, cpu);
219 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid pr pointer\n"));
222 if (!pr->flags.throttling) {
223 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Throttling control is "
224 "unsupported on CPU %d\n", cpu));
227 target_state = p_tstate->target_state;
228 p_throttling = &(pr->throttling);
230 case THROTTLING_PRECHANGE:
232 * Prechange event is used to choose one proper t-state,
233 * which meets the limits of thermal, user and _TPC.
235 p_limit = &pr->limit;
236 if (p_limit->thermal.tx > target_state)
237 target_state = p_limit->thermal.tx;
238 if (p_limit->user.tx > target_state)
239 target_state = p_limit->user.tx;
240 if (pr->throttling_platform_limit > target_state)
241 target_state = pr->throttling_platform_limit;
242 if (target_state >= p_throttling->state_count) {
244 "Exceed the limit of T-state \n");
245 target_state = p_throttling->state_count - 1;
247 p_tstate->target_state = target_state;
248 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PreChange Event:"
249 "target T-state of CPU %d is T%d\n",
252 case THROTTLING_POSTCHANGE:
254 * Postchange event is only used to update the
255 * T-state flag of acpi_processor_throttling.
257 p_throttling->state = target_state;
258 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PostChange Event:"
259 "CPU %d is switched to T%d\n",
264 "Unsupported Throttling notifier event\n");
272 * _TPC - Throttling Present Capabilities
274 static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
276 acpi_status status = 0;
277 unsigned long long tpc = 0;
285 status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc);
286 if (ACPI_FAILURE(status)) {
287 if (status != AE_NOT_FOUND) {
288 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC"));
294 pr->throttling_platform_limit = (int)tpc;
298 int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
301 int throttling_limit;
303 struct acpi_processor_limit *limit;
309 result = acpi_processor_get_platform_limit(pr);
311 /* Throttling Limit is unsupported */
315 throttling_limit = pr->throttling_platform_limit;
316 if (throttling_limit >= pr->throttling.state_count) {
317 /* Uncorrect Throttling Limit */
321 current_state = pr->throttling.state;
322 if (current_state > throttling_limit) {
324 * The current state can meet the requirement of
325 * _TPC limit. But it is reasonable that OSPM changes
326 * t-states from high to low for better performance.
327 * Of course the limit condition of thermal
328 * and user should be considered.
331 target_state = throttling_limit;
332 if (limit->thermal.tx > target_state)
333 target_state = limit->thermal.tx;
334 if (limit->user.tx > target_state)
335 target_state = limit->user.tx;
336 } else if (current_state == throttling_limit) {
338 * Unnecessary to change the throttling state
343 * If the current state is lower than the limit of _TPC, it
344 * will be forced to switch to the throttling state defined
345 * by throttling_platfor_limit.
346 * Because the previous state meets with the limit condition
347 * of thermal and user, it is unnecessary to check it again.
349 target_state = throttling_limit;
351 return acpi_processor_set_throttling(pr, target_state, false);
355 * This function is used to reevaluate whether the T-state is valid
356 * after one CPU is onlined/offlined.
357 * It is noted that it won't reevaluate the following properties for
360 * 2. the number of supported T-state
363 void acpi_processor_reevaluate_tstate(struct acpi_processor *pr,
369 /* When one CPU is offline, the T-state throttling
370 * will be invalidated.
372 pr->flags.throttling = 0;
375 /* the following is to recheck whether the T-state is valid for
378 if (!pr->throttling.state_count) {
379 /* If the number of T-state is invalid, it is
382 pr->flags.throttling = 0;
385 pr->flags.throttling = 1;
387 /* Disable throttling (if enabled). We'll let subsequent
388 * policy (e.g.thermal) decide to lower performance if it
389 * so chooses, but for now we'll crank up the speed.
392 result = acpi_processor_get_throttling(pr);
396 if (pr->throttling.state) {
397 result = acpi_processor_set_throttling(pr, 0, false);
404 pr->flags.throttling = 0;
407 * _PTC - Processor Throttling Control (and status) register location
409 static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
412 acpi_status status = 0;
413 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
414 union acpi_object *ptc = NULL;
415 union acpi_object obj = { 0 };
416 struct acpi_processor_throttling *throttling;
418 status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer);
419 if (ACPI_FAILURE(status)) {
420 if (status != AE_NOT_FOUND) {
421 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PTC"));
426 ptc = (union acpi_object *)buffer.pointer;
427 if (!ptc || (ptc->type != ACPI_TYPE_PACKAGE)
428 || (ptc->package.count != 2)) {
429 printk(KERN_ERR PREFIX "Invalid _PTC data\n");
438 obj = ptc->package.elements[0];
440 if ((obj.type != ACPI_TYPE_BUFFER)
441 || (obj.buffer.length < sizeof(struct acpi_ptc_register))
442 || (obj.buffer.pointer == NULL)) {
443 printk(KERN_ERR PREFIX
444 "Invalid _PTC data (control_register)\n");
448 memcpy(&pr->throttling.control_register, obj.buffer.pointer,
449 sizeof(struct acpi_ptc_register));
455 obj = ptc->package.elements[1];
457 if ((obj.type != ACPI_TYPE_BUFFER)
458 || (obj.buffer.length < sizeof(struct acpi_ptc_register))
459 || (obj.buffer.pointer == NULL)) {
460 printk(KERN_ERR PREFIX "Invalid _PTC data (status_register)\n");
465 memcpy(&pr->throttling.status_register, obj.buffer.pointer,
466 sizeof(struct acpi_ptc_register));
468 throttling = &pr->throttling;
470 if ((throttling->control_register.bit_width +
471 throttling->control_register.bit_offset) > 32) {
472 printk(KERN_ERR PREFIX "Invalid _PTC control register\n");
477 if ((throttling->status_register.bit_width +
478 throttling->status_register.bit_offset) > 32) {
479 printk(KERN_ERR PREFIX "Invalid _PTC status register\n");
485 kfree(buffer.pointer);
491 * _TSS - Throttling Supported States
493 static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
496 acpi_status status = AE_OK;
497 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
498 struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
499 struct acpi_buffer state = { 0, NULL };
500 union acpi_object *tss = NULL;
503 status = acpi_evaluate_object(pr->handle, "_TSS", NULL, &buffer);
504 if (ACPI_FAILURE(status)) {
505 if (status != AE_NOT_FOUND) {
506 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSS"));
511 tss = buffer.pointer;
512 if (!tss || (tss->type != ACPI_TYPE_PACKAGE)) {
513 printk(KERN_ERR PREFIX "Invalid _TSS data\n");
518 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
519 tss->package.count));
521 pr->throttling.state_count = tss->package.count;
522 pr->throttling.states_tss =
523 kmalloc_array(tss->package.count,
524 sizeof(struct acpi_processor_tx_tss),
526 if (!pr->throttling.states_tss) {
531 for (i = 0; i < pr->throttling.state_count; i++) {
533 struct acpi_processor_tx_tss *tx =
534 (struct acpi_processor_tx_tss *)&(pr->throttling.
537 state.length = sizeof(struct acpi_processor_tx_tss);
540 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i));
542 status = acpi_extract_package(&(tss->package.elements[i]),
544 if (ACPI_FAILURE(status)) {
545 ACPI_EXCEPTION((AE_INFO, status, "Invalid _TSS data"));
547 kfree(pr->throttling.states_tss);
551 if (!tx->freqpercentage) {
552 printk(KERN_ERR PREFIX
553 "Invalid _TSS data: freq is zero\n");
555 kfree(pr->throttling.states_tss);
561 kfree(buffer.pointer);
567 * _TSD - T-State Dependencies
569 static int acpi_processor_get_tsd(struct acpi_processor *pr)
572 acpi_status status = AE_OK;
573 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
574 struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
575 struct acpi_buffer state = { 0, NULL };
576 union acpi_object *tsd = NULL;
577 struct acpi_tsd_package *pdomain;
578 struct acpi_processor_throttling *pthrottling;
580 pthrottling = &pr->throttling;
581 pthrottling->tsd_valid_flag = 0;
583 status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer);
584 if (ACPI_FAILURE(status)) {
585 if (status != AE_NOT_FOUND) {
586 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSD"));
591 tsd = buffer.pointer;
592 if (!tsd || (tsd->type != ACPI_TYPE_PACKAGE)) {
593 printk(KERN_ERR PREFIX "Invalid _TSD data\n");
598 if (tsd->package.count != 1) {
599 printk(KERN_ERR PREFIX "Invalid _TSD data\n");
604 pdomain = &(pr->throttling.domain_info);
606 state.length = sizeof(struct acpi_tsd_package);
607 state.pointer = pdomain;
609 status = acpi_extract_package(&(tsd->package.elements[0]),
611 if (ACPI_FAILURE(status)) {
612 printk(KERN_ERR PREFIX "Invalid _TSD data\n");
617 if (pdomain->num_entries != ACPI_TSD_REV0_ENTRIES) {
618 printk(KERN_ERR PREFIX "Unknown _TSD:num_entries\n");
623 if (pdomain->revision != ACPI_TSD_REV0_REVISION) {
624 printk(KERN_ERR PREFIX "Unknown _TSD:revision\n");
629 pthrottling = &pr->throttling;
630 pthrottling->tsd_valid_flag = 1;
631 pthrottling->shared_type = pdomain->coord_type;
632 cpumask_set_cpu(pr->id, pthrottling->shared_cpu_map);
634 * If the coordination type is not defined in ACPI spec,
635 * the tsd_valid_flag will be clear and coordination type
636 * will be forecd as DOMAIN_COORD_TYPE_SW_ALL.
638 if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
639 pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
640 pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
641 pthrottling->tsd_valid_flag = 0;
642 pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL;
646 kfree(buffer.pointer);
650 /* --------------------------------------------------------------------------
652 -------------------------------------------------------------------------- */
653 static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
663 if (!pr->flags.throttling)
667 * We don't care about error returns - we just try to mark
668 * these reserved so that nobody else is confused into thinking
669 * that this region might be unused..
671 * (In particular, allocating the IO range for Cardbus)
673 request_region(pr->throttling.address, 6, "ACPI CPU throttle");
675 pr->throttling.state = 0;
677 duty_mask = pr->throttling.state_count - 1;
679 duty_mask <<= pr->throttling.duty_offset;
683 value = inl(pr->throttling.address);
686 * Compute the current throttling state when throttling is enabled
690 duty_value = value & duty_mask;
691 duty_value >>= pr->throttling.duty_offset;
694 state = pr->throttling.state_count - duty_value;
697 pr->throttling.state = state;
701 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
702 "Throttling state is T%d (%d%% throttling applied)\n",
703 state, pr->throttling.states[state].performance));
709 static int acpi_throttling_rdmsr(u64 *value)
711 u64 msr_high, msr_low;
715 if ((this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_INTEL) ||
716 !this_cpu_has(X86_FEATURE_ACPI)) {
717 printk(KERN_ERR PREFIX
718 "HARDWARE addr space,NOT supported yet\n");
722 rdmsr_safe(MSR_IA32_THERM_CONTROL,
723 (u32 *)&msr_low , (u32 *) &msr_high);
724 msr = (msr_high << 32) | msr_low;
731 static int acpi_throttling_wrmsr(u64 value)
736 if ((this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_INTEL) ||
737 !this_cpu_has(X86_FEATURE_ACPI)) {
738 printk(KERN_ERR PREFIX
739 "HARDWARE addr space,NOT supported yet\n");
742 wrmsr_safe(MSR_IA32_THERM_CONTROL,
743 msr & 0xffffffff, msr >> 32);
749 static int acpi_throttling_rdmsr(u64 *value)
751 printk(KERN_ERR PREFIX
752 "HARDWARE addr space,NOT supported yet\n");
756 static int acpi_throttling_wrmsr(u64 value)
758 printk(KERN_ERR PREFIX
759 "HARDWARE addr space,NOT supported yet\n");
764 static int acpi_read_throttling_status(struct acpi_processor *pr,
767 u32 bit_width, bit_offset;
770 struct acpi_processor_throttling *throttling;
773 throttling = &pr->throttling;
774 switch (throttling->status_register.space_id) {
775 case ACPI_ADR_SPACE_SYSTEM_IO:
776 bit_width = throttling->status_register.bit_width;
777 bit_offset = throttling->status_register.bit_offset;
779 acpi_os_read_port((acpi_io_address) throttling->status_register.
781 (u32) (bit_width + bit_offset));
782 ptc_mask = (1 << bit_width) - 1;
783 *value = (u64) ((ptc_value >> bit_offset) & ptc_mask);
786 case ACPI_ADR_SPACE_FIXED_HARDWARE:
787 ret = acpi_throttling_rdmsr(value);
790 printk(KERN_ERR PREFIX "Unknown addr space %d\n",
791 (u32) (throttling->status_register.space_id));
796 static int acpi_write_throttling_state(struct acpi_processor *pr,
799 u32 bit_width, bit_offset;
802 struct acpi_processor_throttling *throttling;
805 throttling = &pr->throttling;
806 switch (throttling->control_register.space_id) {
807 case ACPI_ADR_SPACE_SYSTEM_IO:
808 bit_width = throttling->control_register.bit_width;
809 bit_offset = throttling->control_register.bit_offset;
810 ptc_mask = (1 << bit_width) - 1;
811 ptc_value = value & ptc_mask;
813 acpi_os_write_port((acpi_io_address) throttling->
814 control_register.address,
815 (u32) (ptc_value << bit_offset),
816 (u32) (bit_width + bit_offset));
819 case ACPI_ADR_SPACE_FIXED_HARDWARE:
820 ret = acpi_throttling_wrmsr(value);
823 printk(KERN_ERR PREFIX "Unknown addr space %d\n",
824 (u32) (throttling->control_register.space_id));
829 static int acpi_get_throttling_state(struct acpi_processor *pr,
834 for (i = 0; i < pr->throttling.state_count; i++) {
835 struct acpi_processor_tx_tss *tx =
836 (struct acpi_processor_tx_tss *)&(pr->throttling.
838 if (tx->control == value)
844 static int acpi_get_throttling_value(struct acpi_processor *pr,
845 int state, u64 *value)
849 if (state >= 0 && state <= pr->throttling.state_count) {
850 struct acpi_processor_tx_tss *tx =
851 (struct acpi_processor_tx_tss *)&(pr->throttling.
853 *value = tx->control;
859 static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
868 if (!pr->flags.throttling)
871 pr->throttling.state = 0;
874 ret = acpi_read_throttling_status(pr, &value);
876 state = acpi_get_throttling_state(pr, value);
878 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
879 "Invalid throttling state, reset\n"));
881 ret = __acpi_processor_set_throttling(pr, state, true,
886 pr->throttling.state = state;
892 static long __acpi_processor_get_throttling(void *data)
894 struct acpi_processor *pr = data;
896 return pr->throttling.acpi_processor_get_throttling(pr);
899 static int acpi_processor_get_throttling(struct acpi_processor *pr)
904 if (!pr->flags.throttling)
908 * This is either called from the CPU hotplug callback of
909 * processor_driver or via the ACPI probe function. In the latter
910 * case the CPU is not guaranteed to be online. Both call sites are
911 * protected against CPU hotplug.
913 if (!cpu_online(pr->id))
916 return call_on_cpu(pr->id, __acpi_processor_get_throttling, pr, false);
919 static int acpi_processor_get_fadt_info(struct acpi_processor *pr)
923 if (!pr->throttling.address) {
924 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
926 } else if (!pr->throttling.duty_width) {
927 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n"));
930 /* TBD: Support duty_cycle values that span bit 4. */
931 else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) {
932 printk(KERN_WARNING PREFIX "duty_cycle spans bit 4\n");
936 pr->throttling.state_count = 1 << acpi_gbl_FADT.duty_width;
939 * Compute state values. Note that throttling displays a linear power
940 * performance relationship (at 50% performance the CPU will consume
941 * 50% power). Values are in 1/10th of a percent to preserve accuracy.
944 step = (1000 / pr->throttling.state_count);
946 for (i = 0; i < pr->throttling.state_count; i++) {
947 pr->throttling.states[i].performance = 1000 - step * i;
948 pr->throttling.states[i].power = 1000 - step * i;
953 static int acpi_processor_set_throttling_fadt(struct acpi_processor *pr,
954 int state, bool force)
963 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
966 if (!pr->flags.throttling)
969 if (!force && (state == pr->throttling.state))
972 if (state < pr->throttling_platform_limit)
975 * Calculate the duty_value and duty_mask.
978 duty_value = pr->throttling.state_count - state;
980 duty_value <<= pr->throttling.duty_offset;
982 /* Used to clear all duty_value bits */
983 duty_mask = pr->throttling.state_count - 1;
985 duty_mask <<= acpi_gbl_FADT.duty_offset;
986 duty_mask = ~duty_mask;
992 * Disable throttling by writing a 0 to bit 4. Note that we must
993 * turn it off before you can change the duty_value.
995 value = inl(pr->throttling.address);
998 outl(value, pr->throttling.address);
1002 * Write the new duty_value and then enable throttling. Note
1003 * that a state value of 0 leaves throttling disabled.
1007 value |= duty_value;
1008 outl(value, pr->throttling.address);
1010 value |= 0x00000010;
1011 outl(value, pr->throttling.address);
1014 pr->throttling.state = state;
1018 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1019 "Throttling state set to T%d (%d%%)\n", state,
1020 (pr->throttling.states[state].performance ? pr->
1021 throttling.states[state].performance / 10 : 0)));
1026 static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
1027 int state, bool force)
1035 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
1038 if (!pr->flags.throttling)
1041 if (!force && (state == pr->throttling.state))
1044 if (state < pr->throttling_platform_limit)
1048 ret = acpi_get_throttling_value(pr, state, &value);
1050 acpi_write_throttling_state(pr, value);
1051 pr->throttling.state = state;
1057 static long acpi_processor_throttling_fn(void *data)
1059 struct acpi_processor_throttling_arg *arg = data;
1060 struct acpi_processor *pr = arg->pr;
1062 return pr->throttling.acpi_processor_set_throttling(pr,
1063 arg->target_state, arg->force);
1066 static int __acpi_processor_set_throttling(struct acpi_processor *pr,
1067 int state, bool force, bool direct)
1071 struct acpi_processor *match_pr;
1072 struct acpi_processor_throttling *p_throttling;
1073 struct acpi_processor_throttling_arg arg;
1074 struct throttling_tstate t_state;
1079 if (!pr->flags.throttling)
1082 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
1085 if (cpu_is_offline(pr->id)) {
1087 * the cpu pointed by pr->id is offline. Unnecessary to change
1088 * the throttling state any more.
1093 t_state.target_state = state;
1094 p_throttling = &(pr->throttling);
1097 * The throttling notifier will be called for every
1098 * affected cpu in order to get one proper T-state.
1099 * The notifier event is THROTTLING_PRECHANGE.
1101 for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) {
1103 acpi_processor_throttling_notifier(THROTTLING_PRECHANGE,
1107 * The function of acpi_processor_set_throttling will be called
1108 * to switch T-state. If the coordination type is SW_ALL or HW_ALL,
1109 * it is necessary to call it for every affected cpu. Otherwise
1110 * it can be called only for the cpu pointed by pr.
1112 if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) {
1114 arg.target_state = state;
1116 ret = call_on_cpu(pr->id, acpi_processor_throttling_fn, &arg,
1120 * When the T-state coordination is SW_ALL or HW_ALL,
1121 * it is necessary to set T-state for every affected
1124 for_each_cpu_and(i, cpu_online_mask,
1125 p_throttling->shared_cpu_map) {
1126 match_pr = per_cpu(processors, i);
1128 * If the pointer is invalid, we will report the
1129 * error message and continue.
1132 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1133 "Invalid Pointer for CPU %d\n", i));
1137 * If the throttling control is unsupported on CPU i,
1138 * we will report the error message and continue.
1140 if (!match_pr->flags.throttling) {
1141 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1142 "Throttling Control is unsupported "
1148 arg.target_state = state;
1150 ret = call_on_cpu(pr->id, acpi_processor_throttling_fn,
1155 * After the set_throttling is called, the
1156 * throttling notifier is called for every
1157 * affected cpu to update the T-states.
1158 * The notifier event is THROTTLING_POSTCHANGE
1160 for_each_cpu_and(i, cpu_online_mask, p_throttling->shared_cpu_map) {
1162 acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE,
1169 int acpi_processor_set_throttling(struct acpi_processor *pr, int state,
1172 return __acpi_processor_set_throttling(pr, state, force, false);
1175 int acpi_processor_get_throttling_info(struct acpi_processor *pr)
1178 struct acpi_processor_throttling *pthrottling;
1180 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1181 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
1182 pr->throttling.address,
1183 pr->throttling.duty_offset,
1184 pr->throttling.duty_width));
1187 * Evaluate _PTC, _TSS and _TPC
1188 * They must all be present or none of them can be used.
1190 if (acpi_processor_get_throttling_control(pr) ||
1191 acpi_processor_get_throttling_states(pr) ||
1192 acpi_processor_get_platform_limit(pr))
1194 pr->throttling.acpi_processor_get_throttling =
1195 &acpi_processor_get_throttling_fadt;
1196 pr->throttling.acpi_processor_set_throttling =
1197 &acpi_processor_set_throttling_fadt;
1198 if (acpi_processor_get_fadt_info(pr))
1201 pr->throttling.acpi_processor_get_throttling =
1202 &acpi_processor_get_throttling_ptc;
1203 pr->throttling.acpi_processor_set_throttling =
1204 &acpi_processor_set_throttling_ptc;
1208 * If TSD package for one CPU can't be parsed successfully, it means
1209 * that this CPU will have no coordination with other CPUs.
1211 if (acpi_processor_get_tsd(pr)) {
1212 pthrottling = &pr->throttling;
1213 pthrottling->tsd_valid_flag = 0;
1214 cpumask_set_cpu(pr->id, pthrottling->shared_cpu_map);
1215 pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL;
1219 * PIIX4 Errata: We don't support throttling on the original PIIX4.
1220 * This shouldn't be an issue as few (if any) mobile systems ever
1223 if (errata.piix4.throttle) {
1224 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1225 "Throttling not supported on PIIX4 A- or B-step\n"));
1229 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
1230 pr->throttling.state_count));
1232 pr->flags.throttling = 1;
1235 * Disable throttling (if enabled). We'll let subsequent policy (e.g.
1236 * thermal) decide to lower performance if it so chooses, but for now
1237 * we'll crank up the speed.
1240 result = acpi_processor_get_throttling(pr);
1244 if (pr->throttling.state) {
1245 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1246 "Disabling throttling (was T%d)\n",
1247 pr->throttling.state));
1248 result = acpi_processor_set_throttling(pr, 0, false);
1255 pr->flags.throttling = 0;