]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ | |
2 | #pragma once | |
3 | ||
4 | #include "forward.h" | |
5 | ||
6 | typedef enum SleepOperation { | |
7 | SLEEP_SUSPEND, | |
8 | SLEEP_HIBERNATE, | |
9 | SLEEP_HYBRID_SLEEP, | |
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. */ | |
13 | ||
14 | SLEEP_SUSPEND_THEN_HIBERNATE, | |
15 | ||
16 | _SLEEP_OPERATION_MAX, | |
17 | _SLEEP_OPERATION_INVALID = -EINVAL, | |
18 | } SleepOperation; | |
19 | ||
20 | const char* sleep_operation_to_string(SleepOperation s) _const_; | |
21 | SleepOperation sleep_operation_from_string(const char *s) _pure_; | |
22 | ||
23 | static inline bool SLEEP_OPERATION_IS_HIBERNATION(SleepOperation operation) { | |
24 | return IN_SET(operation, SLEEP_HIBERNATE, SLEEP_HYBRID_SLEEP); | |
25 | } | |
26 | ||
27 | typedef struct SleepConfig { | |
28 | bool allow[_SLEEP_OPERATION_MAX]; | |
29 | ||
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 */ | |
33 | ||
34 | usec_t hibernate_delay_usec; | |
35 | bool hibernate_on_ac_power; | |
36 | usec_t suspend_estimation_usec; | |
37 | } SleepConfig; | |
38 | ||
39 | SleepConfig* sleep_config_free(SleepConfig *sc); | |
40 | DEFINE_TRIVIAL_CLEANUP_FUNC(SleepConfig*, sleep_config_free); | |
41 | ||
42 | int parse_sleep_config(SleepConfig **sleep_config); | |
43 | ||
44 | bool sleep_needs_mem_sleep(const SleepConfig *sc, SleepOperation operation) _pure_; | |
45 | ||
46 | typedef enum SleepSupport { | |
47 | SLEEP_SUPPORTED, | |
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) */ | |
56 | } SleepSupport; | |
57 | ||
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); | |
61 | } | |
62 | ||
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); |