Skip to content

Commit cba630b

Browse files
committed
Merge branch 'pm-sleep' into pm-docs
2 parents 0c0b6b7 + 726fb6b commit cba630b

File tree

22 files changed

+622
-291
lines changed

22 files changed

+622
-291
lines changed

Documentation/ABI/testing/sysfs-power

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,15 @@ Description:
273273

274274
This output is useful for system wakeup diagnostics of spurious
275275
wakeup interrupts.
276+
277+
What: /sys/power/pm_debug_messages
278+
Date: July 2017
279+
Contact: Rafael J. Wysocki <[email protected]>
280+
Description:
281+
The /sys/power/pm_debug_messages file controls the printing
282+
of debug messages from the system suspend/hiberbation
283+
infrastructure to the kernel log.
284+
285+
Writing a "1" to this file enables the debug messages and
286+
writing a "0" (default) to it disables them. Reads from
287+
this file return the current value.

Documentation/power/states.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ only one way to cause the system to go into the Suspend-To-RAM state (write
3535
The default suspend mode (ie. the one to be used without writing anything into
3636
/sys/power/mem_sleep) is either "deep" (if Suspend-To-RAM is supported) or
3737
"s2idle", but it can be overridden by the value of the "mem_sleep_default"
38-
parameter in the kernel command line.
38+
parameter in the kernel command line. On some ACPI-based systems, depending on
39+
the information in the FADT, the default may be "s2idle" even if Suspend-To-RAM
40+
is supported.
3941

4042
The properties of all of the sleep states are described below.
4143

arch/arm/mach-tegra/cpuidle-tegra114.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int tegra114_idle_power_down(struct cpuidle_device *dev,
6060
return index;
6161
}
6262

63-
static void tegra114_idle_enter_freeze(struct cpuidle_device *dev,
63+
static void tegra114_idle_enter_s2idle(struct cpuidle_device *dev,
6464
struct cpuidle_driver *drv,
6565
int index)
6666
{
@@ -77,7 +77,7 @@ static struct cpuidle_driver tegra_idle_driver = {
7777
#ifdef CONFIG_PM_SLEEP
7878
[1] = {
7979
.enter = tegra114_idle_power_down,
80-
.enter_freeze = tegra114_idle_enter_freeze,
80+
.enter_s2idle = tegra114_idle_enter_s2idle,
8181
.exit_latency = 500,
8282
.target_residency = 1000,
8383
.flags = CPUIDLE_FLAG_TIMER_STOP,

drivers/acpi/processor_idle.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ static int acpi_idle_enter(struct cpuidle_device *dev,
789789
return index;
790790
}
791791

792-
static void acpi_idle_enter_freeze(struct cpuidle_device *dev,
792+
static void acpi_idle_enter_s2idle(struct cpuidle_device *dev,
793793
struct cpuidle_driver *drv, int index)
794794
{
795795
struct acpi_processor_cx *cx = per_cpu(acpi_cstate[index], dev->cpu);
@@ -867,14 +867,14 @@ static int acpi_processor_setup_cstates(struct acpi_processor *pr)
867867
drv->safe_state_index = count;
868868
}
869869
/*
870-
* Halt-induced C1 is not good for ->enter_freeze, because it
870+
* Halt-induced C1 is not good for ->enter_s2idle, because it
871871
* re-enables interrupts on exit. Moreover, C1 is generally not
872872
* particularly interesting from the suspend-to-idle angle, so
873873
* avoid C1 and the situations in which we may need to fall back
874874
* to it altogether.
875875
*/
876876
if (cx->type != ACPI_STATE_C1 && !acpi_idle_fallback_to_c1(pr))
877-
state->enter_freeze = acpi_idle_enter_freeze;
877+
state->enter_s2idle = acpi_idle_enter_s2idle;
878878

879879
count++;
880880
if (count == CPUIDLE_STATE_MAX)

drivers/acpi/sleep.c

Lines changed: 188 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ static const struct acpi_device_id lps0_device_ids[] = {
669669

670670
#define ACPI_LPS0_DSM_UUID "c4eb40a0-6cd2-11e2-bcfd-0800200c9a66"
671671

672+
#define ACPI_LPS0_GET_DEVICE_CONSTRAINTS 1
672673
#define ACPI_LPS0_SCREEN_OFF 3
673674
#define ACPI_LPS0_SCREEN_ON 4
674675
#define ACPI_LPS0_ENTRY 5
@@ -680,6 +681,166 @@ static acpi_handle lps0_device_handle;
680681
static guid_t lps0_dsm_guid;
681682
static char lps0_dsm_func_mask;
682683

684+
/* Device constraint entry structure */
685+
struct lpi_device_info {
686+
char *name;
687+
int enabled;
688+
union acpi_object *package;
689+
};
690+
691+
/* Constraint package structure */
692+
struct lpi_device_constraint {
693+
int uid;
694+
int min_dstate;
695+
int function_states;
696+
};
697+
698+
struct lpi_constraints {
699+
acpi_handle handle;
700+
int min_dstate;
701+
};
702+
703+
static struct lpi_constraints *lpi_constraints_table;
704+
static int lpi_constraints_table_size;
705+
706+
static void lpi_device_get_constraints(void)
707+
{
708+
union acpi_object *out_obj;
709+
int i;
710+
711+
out_obj = acpi_evaluate_dsm_typed(lps0_device_handle, &lps0_dsm_guid,
712+
1, ACPI_LPS0_GET_DEVICE_CONSTRAINTS,
713+
NULL, ACPI_TYPE_PACKAGE);
714+
715+
acpi_handle_debug(lps0_device_handle, "_DSM function 1 eval %s\n",
716+
out_obj ? "successful" : "failed");
717+
718+
if (!out_obj)
719+
return;
720+
721+
lpi_constraints_table = kcalloc(out_obj->package.count,
722+
sizeof(*lpi_constraints_table),
723+
GFP_KERNEL);
724+
if (!lpi_constraints_table)
725+
goto free_acpi_buffer;
726+
727+
acpi_handle_debug(lps0_device_handle, "LPI: constraints list begin:\n");
728+
729+
for (i = 0; i < out_obj->package.count; i++) {
730+
struct lpi_constraints *constraint;
731+
acpi_status status;
732+
union acpi_object *package = &out_obj->package.elements[i];
733+
struct lpi_device_info info = { };
734+
int package_count = 0, j;
735+
736+
if (!package)
737+
continue;
738+
739+
for (j = 0; j < package->package.count; ++j) {
740+
union acpi_object *element =
741+
&(package->package.elements[j]);
742+
743+
switch (element->type) {
744+
case ACPI_TYPE_INTEGER:
745+
info.enabled = element->integer.value;
746+
break;
747+
case ACPI_TYPE_STRING:
748+
info.name = element->string.pointer;
749+
break;
750+
case ACPI_TYPE_PACKAGE:
751+
package_count = element->package.count;
752+
info.package = element->package.elements;
753+
break;
754+
}
755+
}
756+
757+
if (!info.enabled || !info.package || !info.name)
758+
continue;
759+
760+
constraint = &lpi_constraints_table[lpi_constraints_table_size];
761+
762+
status = acpi_get_handle(NULL, info.name, &constraint->handle);
763+
if (ACPI_FAILURE(status))
764+
continue;
765+
766+
acpi_handle_debug(lps0_device_handle,
767+
"index:%d Name:%s\n", i, info.name);
768+
769+
constraint->min_dstate = -1;
770+
771+
for (j = 0; j < package_count; ++j) {
772+
union acpi_object *info_obj = &info.package[j];
773+
union acpi_object *cnstr_pkg;
774+
union acpi_object *obj;
775+
struct lpi_device_constraint dev_info;
776+
777+
switch (info_obj->type) {
778+
case ACPI_TYPE_INTEGER:
779+
/* version */
780+
break;
781+
case ACPI_TYPE_PACKAGE:
782+
if (info_obj->package.count < 2)
783+
break;
784+
785+
cnstr_pkg = info_obj->package.elements;
786+
obj = &cnstr_pkg[0];
787+
dev_info.uid = obj->integer.value;
788+
obj = &cnstr_pkg[1];
789+
dev_info.min_dstate = obj->integer.value;
790+
791+
acpi_handle_debug(lps0_device_handle,
792+
"uid:%d min_dstate:%s\n",
793+
dev_info.uid,
794+
acpi_power_state_string(dev_info.min_dstate));
795+
796+
constraint->min_dstate = dev_info.min_dstate;
797+
break;
798+
}
799+
}
800+
801+
if (constraint->min_dstate < 0) {
802+
acpi_handle_debug(lps0_device_handle,
803+
"Incomplete constraint defined\n");
804+
continue;
805+
}
806+
807+
lpi_constraints_table_size++;
808+
}
809+
810+
acpi_handle_debug(lps0_device_handle, "LPI: constraints list end\n");
811+
812+
free_acpi_buffer:
813+
ACPI_FREE(out_obj);
814+
}
815+
816+
static void lpi_check_constraints(void)
817+
{
818+
int i;
819+
820+
for (i = 0; i < lpi_constraints_table_size; ++i) {
821+
struct acpi_device *adev;
822+
823+
if (acpi_bus_get_device(lpi_constraints_table[i].handle, &adev))
824+
continue;
825+
826+
acpi_handle_debug(adev->handle,
827+
"LPI: required min power state:%s current power state:%s\n",
828+
acpi_power_state_string(lpi_constraints_table[i].min_dstate),
829+
acpi_power_state_string(adev->power.state));
830+
831+
if (!adev->flags.power_manageable) {
832+
acpi_handle_info(adev->handle, "LPI: Device not power manageble\n");
833+
continue;
834+
}
835+
836+
if (adev->power.state < lpi_constraints_table[i].min_dstate)
837+
acpi_handle_info(adev->handle,
838+
"LPI: Constraint not met; min power state:%s current power state:%s\n",
839+
acpi_power_state_string(lpi_constraints_table[i].min_dstate),
840+
acpi_power_state_string(adev->power.state));
841+
}
842+
}
843+
683844
static void acpi_sleep_run_lps0_dsm(unsigned int func)
684845
{
685846
union acpi_object *out_obj;
@@ -714,6 +875,12 @@ static int lps0_device_attach(struct acpi_device *adev,
714875
if ((bitmask & ACPI_S2IDLE_FUNC_MASK) == ACPI_S2IDLE_FUNC_MASK) {
715876
lps0_dsm_func_mask = bitmask;
716877
lps0_device_handle = adev->handle;
878+
/*
879+
* Use suspend-to-idle by default if the default
880+
* suspend mode was not set from the command line.
881+
*/
882+
if (mem_sleep_default > PM_SUSPEND_MEM)
883+
mem_sleep_current = PM_SUSPEND_TO_IDLE;
717884
}
718885

719886
acpi_handle_debug(adev->handle, "_DSM function mask: 0x%x\n",
@@ -723,6 +890,9 @@ static int lps0_device_attach(struct acpi_device *adev,
723890
"_DSM function 0 evaluation failed\n");
724891
}
725892
ACPI_FREE(out_obj);
893+
894+
lpi_device_get_constraints();
895+
726896
return 0;
727897
}
728898

@@ -731,14 +901,14 @@ static struct acpi_scan_handler lps0_handler = {
731901
.attach = lps0_device_attach,
732902
};
733903

734-
static int acpi_freeze_begin(void)
904+
static int acpi_s2idle_begin(void)
735905
{
736906
acpi_scan_lock_acquire();
737907
s2idle_in_progress = true;
738908
return 0;
739909
}
740910

741-
static int acpi_freeze_prepare(void)
911+
static int acpi_s2idle_prepare(void)
742912
{
743913
if (lps0_device_handle) {
744914
acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_OFF);
@@ -758,8 +928,12 @@ static int acpi_freeze_prepare(void)
758928
return 0;
759929
}
760930

761-
static void acpi_freeze_wake(void)
931+
static void acpi_s2idle_wake(void)
762932
{
933+
934+
if (pm_debug_messages_on)
935+
lpi_check_constraints();
936+
763937
/*
764938
* If IRQD_WAKEUP_ARMED is not set for the SCI at this point, it means
765939
* that the SCI has triggered while suspended, so cancel the wakeup in
@@ -772,7 +946,7 @@ static void acpi_freeze_wake(void)
772946
}
773947
}
774948

775-
static void acpi_freeze_sync(void)
949+
static void acpi_s2idle_sync(void)
776950
{
777951
/*
778952
* Process all pending events in case there are any wakeup ones.
@@ -785,7 +959,7 @@ static void acpi_freeze_sync(void)
785959
s2idle_wakeup = false;
786960
}
787961

788-
static void acpi_freeze_restore(void)
962+
static void acpi_s2idle_restore(void)
789963
{
790964
if (acpi_sci_irq_valid())
791965
disable_irq_wake(acpi_sci_irq);
@@ -798,19 +972,19 @@ static void acpi_freeze_restore(void)
798972
}
799973
}
800974

801-
static void acpi_freeze_end(void)
975+
static void acpi_s2idle_end(void)
802976
{
803977
s2idle_in_progress = false;
804978
acpi_scan_lock_release();
805979
}
806980

807-
static const struct platform_freeze_ops acpi_freeze_ops = {
808-
.begin = acpi_freeze_begin,
809-
.prepare = acpi_freeze_prepare,
810-
.wake = acpi_freeze_wake,
811-
.sync = acpi_freeze_sync,
812-
.restore = acpi_freeze_restore,
813-
.end = acpi_freeze_end,
981+
static const struct platform_s2idle_ops acpi_s2idle_ops = {
982+
.begin = acpi_s2idle_begin,
983+
.prepare = acpi_s2idle_prepare,
984+
.wake = acpi_s2idle_wake,
985+
.sync = acpi_s2idle_sync,
986+
.restore = acpi_s2idle_restore,
987+
.end = acpi_s2idle_end,
814988
};
815989

816990
static void acpi_sleep_suspend_setup(void)
@@ -825,7 +999,7 @@ static void acpi_sleep_suspend_setup(void)
825999
&acpi_suspend_ops_old : &acpi_suspend_ops);
8261000

8271001
acpi_scan_add_handler(&lps0_handler);
828-
freeze_set_ops(&acpi_freeze_ops);
1002+
s2idle_set_ops(&acpi_s2idle_ops);
8291003
}
8301004

8311005
#else /* !CONFIG_SUSPEND */

0 commit comments

Comments
 (0)