1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
7 typedef enum SleepOperation
{
11 _SLEEP_OPERATION_CONFIG_MAX
,
12 /* The operations above require configuration for mode and state. The ones below are "combined"
13 * operations that use config from those individual operations. */
15 SLEEP_SUSPEND_THEN_HIBERNATE
,
18 _SLEEP_OPERATION_INVALID
= -EINVAL
,
21 const char* sleep_operation_to_string(SleepOperation s
) _const_
;
22 SleepOperation
sleep_operation_from_string(const char *s
) _pure_
;
24 static inline bool SLEEP_OPERATION_IS_HIBERNATION(SleepOperation operation
) {
25 return IN_SET(operation
, SLEEP_HIBERNATE
, SLEEP_HYBRID_SLEEP
);
28 typedef struct SleepConfig
{
29 bool allow
[_SLEEP_OPERATION_MAX
];
31 char **states
[_SLEEP_OPERATION_CONFIG_MAX
];
32 char **modes
[_SLEEP_OPERATION_CONFIG_MAX
]; /* Power mode after writing hibernation image (/sys/power/disk) */
33 char **mem_modes
; /* /sys/power/mem_sleep */
35 usec_t hibernate_delay_usec
;
36 usec_t suspend_estimation_usec
;
39 SleepConfig
* sleep_config_free(SleepConfig
*sc
);
40 DEFINE_TRIVIAL_CLEANUP_FUNC(SleepConfig
*, sleep_config_free
);
42 int parse_sleep_config(SleepConfig
**sleep_config
);
44 static inline bool SLEEP_NEEDS_MEM_SLEEP(const SleepConfig
*sc
, SleepOperation operation
) {
46 assert(operation
>= 0 && operation
< _SLEEP_OPERATION_CONFIG_MAX
);
48 /* As per https://docs.kernel.org/admin-guide/pm/sleep-states.html#basic-sysfs-interfaces-for-system-suspend-and-hibernation,
49 * /sys/power/mem_sleep is honored if /sys/power/state is set to "mem" (common for suspend)
50 * or /sys/power/disk is set to "suspend" (hybrid-sleep). */
52 return strv_contains(sc
->states
[operation
], "mem") ||
53 strv_contains(sc
->modes
[operation
], "suspend");
56 typedef enum SleepSupport
{
58 SLEEP_DISABLED
, /* Disabled in SleepConfig.allow */
59 SLEEP_NOT_CONFIGURED
, /* SleepConfig.states is not configured */
60 SLEEP_STATE_OR_MODE_NOT_SUPPORTED
, /* SleepConfig.states/modes are not supported by kernel */
61 SLEEP_RESUME_NOT_SUPPORTED
,
62 SLEEP_NOT_ENOUGH_SWAP_SPACE
,
63 SLEEP_ALARM_NOT_SUPPORTED
, /* CLOCK_BOOTTIME_ALARM is unsupported by kernel (only used by s2h) */
66 int sleep_supported_full(SleepOperation operation
, SleepSupport
*ret_support
);
67 static inline int sleep_supported(SleepOperation operation
) {
68 return sleep_supported_full(operation
, NULL
);
71 /* Only for test-sleep-config */
72 int sleep_state_supported(char * const *states
);
73 int sleep_mode_supported(const char *path
, char * const *modes
);