Debian Codegraph @

src/shared/sleep-config.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "shared-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 DECLARE_STRING_TABLE_LOOKUP(sleep_operation, SleepOperation);
21
22 static inline bool SLEEP_OPERATION_IS_HIBERNATION(SleepOperation operation) {
23 return IN_SET(operation, SLEEP_HIBERNATE, SLEEP_HYBRID_SLEEP);
24 }
25
26 typedef struct SleepConfig {
27 bool allow[_SLEEP_OPERATION_MAX];
28
29 char **states[_SLEEP_OPERATION_CONFIG_MAX];
30 char **modes[_SLEEP_OPERATION_CONFIG_MAX]; /* Power mode after writing hibernation image (/sys/power/disk) */
31 char **mem_modes; /* /sys/power/mem_sleep */
32
33 usec_t hibernate_delay_usec;
34 bool hibernate_on_ac_power;
35 usec_t suspend_estimation_usec;
36 } SleepConfig;
37
38 SleepConfig* sleep_config_free(SleepConfig *sc);
39 DEFINE_TRIVIAL_CLEANUP_FUNC(SleepConfig*, sleep_config_free);
40
41 int parse_sleep_config(SleepConfig **ret);
42
43 bool sleep_needs_mem_sleep(const SleepConfig *sc, SleepOperation operation) _pure_;
44
45 typedef enum SleepSupport {
46 SLEEP_SUPPORTED,
47 SLEEP_DISABLED, /* Disabled in SleepConfig.allow */
48 SLEEP_NOT_CONFIGURED, /* SleepConfig.states is not configured */
49 SLEEP_STATE_OR_MODE_NOT_SUPPORTED, /* SleepConfig.states/modes are not supported by kernel */
50 SLEEP_RESUME_NOT_SUPPORTED,
51 SLEEP_RESUME_DEVICE_MISSING, /* resume= is specified, but the device cannot be found in /proc/swaps */
52 SLEEP_RESUME_MISCONFIGURED, /* resume= is not set yet resume_offset= is configured */
53 SLEEP_NOT_ENOUGH_SWAP_SPACE,
54 SLEEP_ALARM_NOT_SUPPORTED, /* CLOCK_BOOTTIME_ALARM is unsupported by kernel (only used by s2h) */
55 } SleepSupport;
56
57 int sleep_supported_full(SleepOperation operation, SleepSupport *ret_support);
58 static inline int sleep_supported(SleepOperation operation) {
59 return sleep_supported_full(operation, NULL);
60 }
61
62 /* Only for test-sleep-config */
63 int sleep_state_supported(char * const *states);
64 int sleep_mode_supported(const char *path, char * const *modes);