]>
| Commit | Line | Data |
|---|---|---|
| 54d7fcc6 MY |
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 | #pragma once | |
| 3 | ||
| f102bc3e | 4 | #include "shared-forward.h" |
| 54d7fcc6 | 5 | |
| 54d7fcc6 MY |
6 | typedef enum SleepOperation { |
| 7 | SLEEP_SUSPEND, | |
| 8 | SLEEP_HIBERNATE, | |
| 9 | SLEEP_HYBRID_SLEEP, | |
| 087a25d2 MY |
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 | ||
| 54d7fcc6 | 14 | SLEEP_SUSPEND_THEN_HIBERNATE, |
| 087a25d2 | 15 | |
| 54d7fcc6 MY |
16 | _SLEEP_OPERATION_MAX, |
| 17 | _SLEEP_OPERATION_INVALID = -EINVAL, | |
| 18 | } SleepOperation; | |
| 19 | ||
| 087a25d2 MY |
20 | const char* sleep_operation_to_string(SleepOperation s) _const_; |
| 21 | SleepOperation sleep_operation_from_string(const char *s) _pure_; | |
| 22 | ||
| 792dd6f4 | 23 | static inline bool SLEEP_OPERATION_IS_HIBERNATION(SleepOperation operation) { |
| e024cdd2 MY |
24 | return IN_SET(operation, SLEEP_HIBERNATE, SLEEP_HYBRID_SLEEP); |
| 25 | } | |
| 26 | ||
| 54d7fcc6 MY |
27 | typedef struct SleepConfig { |
| 28 | bool allow[_SLEEP_OPERATION_MAX]; | |
| 563ef8f9 | 29 | |
| 087a25d2 | 30 | char **states[_SLEEP_OPERATION_CONFIG_MAX]; |
| a2124b35 MY |
31 | char **modes[_SLEEP_OPERATION_CONFIG_MAX]; /* Power mode after writing hibernation image (/sys/power/disk) */ |
| 32 | char **mem_modes; /* /sys/power/mem_sleep */ | |
| 087a25d2 | 33 | |
| 54d7fcc6 | 34 | usec_t hibernate_delay_usec; |
| 2d00f4c3 | 35 | bool hibernate_on_ac_power; |
| 54d7fcc6 MY |
36 | usec_t suspend_estimation_usec; |
| 37 | } SleepConfig; | |
| 38 | ||
| 087a25d2 MY |
39 | SleepConfig* sleep_config_free(SleepConfig *sc); |
| 40 | DEFINE_TRIVIAL_CLEANUP_FUNC(SleepConfig*, sleep_config_free); | |
| 54d7fcc6 MY |
41 | |
| 42 | int parse_sleep_config(SleepConfig **sleep_config); | |
| 43 | ||
| dbef7bcf | 44 | bool sleep_needs_mem_sleep(const SleepConfig *sc, SleepOperation operation) _pure_; |
| a2124b35 | 45 | |
| a0f6d74e MY |
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 */ | |
| 805deec0 | 51 | SLEEP_RESUME_NOT_SUPPORTED, |
| 40eb83a8 | 52 | SLEEP_RESUME_DEVICE_MISSING, /* resume= is specified, but the device cannot be found in /proc/swaps */ |
| 3fce141c | 53 | SLEEP_RESUME_MISCONFIGURED, /* resume= is not set yet resume_offset= is configured */ |
| a0f6d74e MY |
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 | } | |
| 23577f44 MY |
62 | |
| 63 | /* Only for test-sleep-config */ | |
| b0e3b85a MY |
64 | int sleep_state_supported(char * const *states); |
| 65 | int sleep_mode_supported(const char *path, char * const *modes); |