31 #include <linux/kernel.h>
32 #include <linux/module.h>
35 #include <linux/slab.h>
39 #include <linux/sched.h>
56 #include <asm/uaccess.h>
60 #include <asm/processor.h>
62 #define PREFIX "ACPI: "
64 #define ACPI_PROCESSOR_CLASS "processor"
65 #define _COMPONENT ACPI_PROCESSOR_COMPONENT
67 #define PM_TIMER_TICK_NS (1000000000ULL/PM_TIMER_FREQUENCY)
70 #define PM_TIMER_TICKS_TO_US(p) (((p) * 1000)/(PM_TIMER_FREQUENCY/1000))
84 static int disabled_by_idle_boot_param(
void)
103 " Override with \"processor.max_cstate=%d\"\n", id->
ident,
106 max_cstate = (
long)id->driver_data;
114 { set_max_cstate,
"Clevo 5600D", {
118 { set_max_cstate,
"Pavilion zv5000", {
122 { set_max_cstate,
"Asus L8400B", {
134 static void acpi_safe_halt(
void)
142 if (!need_resched()) {
149 #ifdef ARCH_APICTIMER_STOPS_ON_C3
176 if (cx->
type >= type)
180 static void __lapic_timer_propagate_broadcast(
void *
arg)
186 CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
191 static void lapic_timer_propagate_broadcast(
struct acpi_processor *pr)
198 static void lapic_timer_state_broadcast(
struct acpi_processor *pr,
202 int state = cx - pr->
power.states;
204 if (state >= pr->
power.timer_broadcast_on_state) {
207 reason = broadcast ? CLOCK_EVT_NOTIFY_BROADCAST_ENTER :
208 CLOCK_EVT_NOTIFY_BROADCAST_EXIT;
215 static void lapic_timer_check_state(
int state,
struct acpi_processor *pr,
217 static void lapic_timer_propagate_broadcast(
struct acpi_processor *pr) { }
218 static void lapic_timer_state_broadcast(
struct acpi_processor *pr,
226 static u32 saved_bm_rld;
228 static void acpi_idle_bm_rld_save(
void)
232 static void acpi_idle_bm_rld_restore(
void)
238 if (resumed_bm_rld != saved_bm_rld)
244 acpi_idle_bm_rld_save();
250 acpi_idle_bm_rld_restore();
254 #if defined(CONFIG_X86)
255 static void tsc_check_state(
int state)
275 static void tsc_check_state(
int state) {
return; }
278 static int acpi_processor_get_power_info_fadt(
struct acpi_processor *pr)
291 #ifndef CONFIG_HOTPLUG_CPU
332 "lvl2[0x%08x] lvl3[0x%08x]\n",
339 static int acpi_processor_get_power_info_default(
struct acpi_processor *pr)
353 static int acpi_processor_get_power_info_cst(
struct acpi_processor *pr)
383 count = cst->
package.elements[0].integer.value;
386 if (count < 1 || count != cst->
package.count - 1) {
393 pr->
flags.has_cst = 1;
395 for (i = 1; i <=
count; i++) {
401 memset(&cx, 0,
sizeof(cx));
403 element = &(cst->
package.elements[
i]);
407 if (element->
package.count != 4)
410 obj = &(element->
package.elements[0]);
422 obj = &(element->
package.elements[1]);
435 cx.
index = current_count + 1;
440 (pr->
id, &cx, reg) == 0) {
478 obj = &(element->
package.elements[2]);
484 obj = &(element->
package.elements[3]);
489 memcpy(&(pr->
power.states[current_count]), &cx,
sizeof(cx));
497 "Limiting number of power states to max (%d)\n",
500 "Please increase ACPI_PROCESSOR_MAX_POWER if needed.\n");
509 if (current_count < 2)
518 static void acpi_processor_power_verify_c3(
struct acpi_processor *pr,
521 static int bm_check_flag = -1;
522 static int bm_control_flag = -1;
535 else if (
errata.piix4.fdma) {
537 "C3 not supported on PIIX4 with Type-F DMA\n"));
542 if (bm_check_flag == -1) {
545 bm_check_flag = pr->
flags.bm_check;
546 bm_control_flag = pr->
flags.bm_control;
548 pr->
flags.bm_check = bm_check_flag;
549 pr->
flags.bm_control = bm_control_flag;
552 if (pr->
flags.bm_check) {
553 if (!pr->
flags.bm_control) {
554 if (pr->
flags.has_cst != 1) {
557 "C3 support requires BM control\n"));
562 "C3 support without BM control\n"));
572 "Cache invalidation should work properly"
573 " for C3 to be enabled on SMP systems\n"));
602 unsigned int working = 0;
621 acpi_processor_power_verify_c3(pr, cx);
627 lapic_timer_check_state(i, pr, cx);
628 tsc_check_state(cx->
type);
632 lapic_timer_propagate_broadcast(pr);
637 static int acpi_processor_get_power_info(
struct acpi_processor *pr)
649 result = acpi_processor_get_power_info_cst(pr);
651 result = acpi_processor_get_power_info_fadt(pr);
656 acpi_processor_get_power_info_default(pr);
658 pr->
power.count = acpi_processor_power_verify(pr);
665 if (pr->
power.states[i].valid) {
678 static int acpi_idle_bm_check(
void)
682 if (bm_check_disable)
693 else if (
errata.piix4.bmisx) {
753 lapic_timer_state_broadcast(pr, cx, 1);
755 acpi_idle_do_entry(cx);
757 idle_time = ktime_to_us(ktime_sub(kt2, kt1));
763 lapic_timer_state_broadcast(pr, cx, 0);
774 static int acpi_idle_play_dead(
struct cpuidle_device *dev,
int index)
841 lapic_timer_state_broadcast(pr, cx, 1);
848 sched_clock_idle_sleep_event();
849 acpi_idle_do_entry(cx);
851 idle_time_ns = ktime_to_ns(ktime_sub(kt2, kt1));
852 idle_time = idle_time_ns;
859 sched_clock_idle_wakeup_event(idle_time_ns);
865 lapic_timer_state_broadcast(pr, cx, 0);
869 static int c3_cpu_count;
930 sched_clock_idle_sleep_event();
935 lapic_timer_state_broadcast(pr, cx, 1);
948 if (pr->
flags.bm_check && pr->
flags.bm_control) {
955 }
else if (!pr->
flags.bm_check) {
959 acpi_idle_do_entry(cx);
962 if (pr->
flags.bm_check && pr->
flags.bm_control) {
969 idle_time_ns = ktime_to_ns(ktime_sub(kt2, kt1));
970 idle_time = idle_time_ns;
977 sched_clock_idle_wakeup_event(idle_time_ns);
983 lapic_timer_state_broadcast(pr, cx, 0);
998 static int acpi_processor_setup_cpuidle_cx(
struct acpi_processor *pr)
1005 if (!pr->
flags.power_setup_done)
1008 if (pr->
flags.power == 0) {
1014 if (max_cstate == 0)
1017 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1018 cx = &pr->
power.states[
i];
1024 #ifdef CONFIG_HOTPLUG_CPU
1026 !pr->
flags.has_cst &&
1031 cpuidle_set_statedata(state_usage, cx);
1052 static int acpi_processor_setup_cpuidle_states(
struct acpi_processor *pr)
1059 if (!pr->
flags.power_setup_done)
1062 if (pr->
flags.power == 0)
1067 drv->
states[
i].name[0] =
'\0';
1068 drv->
states[
i].desc[0] =
'\0';
1071 if (max_cstate == 0)
1074 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1075 cx = &pr->
power.states[
i];
1080 #ifdef CONFIG_HOTPLUG_CPU
1082 !pr->
flags.has_cst &&
1099 state->
enter = acpi_idle_enter_c1;
1106 state->
enter = acpi_idle_enter_simple;
1114 acpi_idle_enter_bm :
1115 acpi_idle_enter_simple;
1120 if (count == CPUIDLE_STATE_MAX)
1137 if (disabled_by_idle_boot_param())
1147 if (!pr->
flags.power_setup_done)
1150 dev =
per_cpu(acpi_cpuidle_device, pr->
id);
1153 acpi_processor_get_power_info(pr);
1154 if (pr->
flags.power) {
1155 acpi_processor_setup_cpuidle_cx(pr);
1169 if (disabled_by_idle_boot_param())
1178 if (!pr->
flags.power_setup_done)
1195 _pr =
per_cpu(processors, cpu);
1196 if (!_pr || !_pr->
flags.power_setup_done)
1198 dev =
per_cpu(acpi_cpuidle_device, cpu);
1203 acpi_processor_setup_cpuidle_states(pr);
1207 _pr =
per_cpu(processors, cpu);
1208 if (!_pr || !_pr->
flags.power_setup_done)
1210 acpi_processor_get_power_info(_pr);
1211 if (_pr->
flags.power) {
1212 acpi_processor_setup_cpuidle_cx(_pr);
1213 dev =
per_cpu(acpi_cpuidle_device, cpu);
1224 static int acpi_processor_registered;
1231 static int first_run;
1233 if (disabled_by_idle_boot_param())
1238 max_cstate = acpi_processor_cstate_check(max_cstate);
1241 "ACPI: processor limited to max C-state %d\n",
1254 "Notifying BIOS of _CST ability failed"));
1258 acpi_processor_get_power_info(pr);
1259 pr->
flags.power_setup_done = 1;
1266 if (pr->
flags.power) {
1268 if (!acpi_processor_registered) {
1269 acpi_processor_setup_cpuidle_states(pr);
1274 acpi_idle_driver.
name);
1282 acpi_processor_setup_cpuidle_cx(pr);
1289 if (acpi_processor_registered == 0)
1293 acpi_processor_registered++;
1302 if (disabled_by_idle_boot_param())
1305 if (pr->
flags.power) {
1307 acpi_processor_registered--;
1308 if (acpi_processor_registered == 0)
1312 pr->
flags.power_setup_done = 0;