1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 typedef enum SleepOperation
{
10 _SLEEP_OPERATION_CONFIG_MAX
,
11 /* The operations above require configuration for mode and state. The ones below are "combined"
12 * operations that use config from those individual operations. */
14 SLEEP_SUSPEND_THEN_HIBERNATE
,
17 _SLEEP_OPERATION_INVALID
= -EINVAL
,
20 const char* sleep_operation_to_string(SleepOperation s
) _const_
;
21 SleepOperation
sleep_operation_from_string(const char *s
) _pure_
;
23 static inline bool SLEEP_OPERATION_IS_HIBERNATION(SleepOperation operation
) {
24 return IN_SET(operation
, SLEEP_HIBERNATE
, SLEEP_HYBRID_SLEEP
);
27 typedef struct SleepConfig
{
28 bool allow
[_SLEEP_OPERATION_MAX
];
30 char **states
[_SLEEP_OPERATION_CONFIG_MAX
];
31 char **modes
[_SLEEP_OPERATION_CONFIG_MAX
]; /* Power mode after writing hibernation image (/sys/power/disk) */
32 char **mem_modes
; /* /sys/power/mem_sleep */
34 usec_t hibernate_delay_usec
;
35 bool hibernate_on_ac_power
;
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 bool sleep_needs_mem_sleep(const SleepConfig
*sc
, SleepOperation operation
) _pure_
;
46 typedef enum SleepSupport
{
48 SLEEP_DISABLED
, /* Disabled in SleepConfig.allow */
49 SLEEP_NOT_CONFIGURED
, /* SleepConfig.states is not configured */
50 SLEEP_STATE_OR_MODE_NOT_SUPPORTED
, /* SleepConfig.states/modes are not supported by kernel */
51 SLEEP_RESUME_NOT_SUPPORTED
,
52 SLEEP_RESUME_DEVICE_MISSING
, /* resume= is specified, but the device cannot be found in /proc/swaps */
53 SLEEP_RESUME_MISCONFIGURED
, /* resume= is not set yet resume_offset= is configured */
54 SLEEP_NOT_ENOUGH_SWAP_SPACE
,
55 SLEEP_ALARM_NOT_SUPPORTED
, /* CLOCK_BOOTTIME_ALARM is unsupported by kernel (only used by s2h) */
58 int sleep_supported_full(SleepOperation operation
, SleepSupport
*ret_support
);
59 static inline int sleep_supported(SleepOperation operation
) {
60 return sleep_supported_full(operation
, NULL
);
63 /* Only for test-sleep-config */
64 int sleep_state_supported(char * const *states
);
65 int sleep_mode_supported(const char *path
, char * const *modes
);