summaryrefslogtreecommitdiffstats
path: root/src/shared/sleep-config.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/shared/sleep-config.h
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/shared/sleep-config.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/shared/sleep-config.h b/src/shared/sleep-config.h
new file mode 100644
index 0000000..bc5aeb9
--- /dev/null
+++ b/src/shared/sleep-config.h
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "time-util.h"
+
+typedef enum SleepOperation {
+ SLEEP_SUSPEND,
+ SLEEP_HIBERNATE,
+ SLEEP_HYBRID_SLEEP,
+ _SLEEP_OPERATION_CONFIG_MAX,
+ /* The operations above require configuration for mode and state. The ones below are "combined"
+ * operations that use config from those individual operations. */
+
+ SLEEP_SUSPEND_THEN_HIBERNATE,
+
+ _SLEEP_OPERATION_MAX,
+ _SLEEP_OPERATION_INVALID = -EINVAL,
+} SleepOperation;
+
+const char* sleep_operation_to_string(SleepOperation s) _const_;
+SleepOperation sleep_operation_from_string(const char *s) _pure_;
+
+static inline bool sleep_operation_is_hibernation(SleepOperation operation) {
+ return IN_SET(operation, SLEEP_HIBERNATE, SLEEP_HYBRID_SLEEP);
+}
+
+typedef struct SleepConfig {
+ bool allow[_SLEEP_OPERATION_MAX];
+
+ char **states[_SLEEP_OPERATION_CONFIG_MAX];
+ char **modes[_SLEEP_OPERATION_CONFIG_MAX]; /* Power mode after writing hibernation image */
+
+ usec_t hibernate_delay_usec;
+ usec_t suspend_estimation_usec;
+} SleepConfig;
+
+SleepConfig* sleep_config_free(SleepConfig *sc);
+DEFINE_TRIVIAL_CLEANUP_FUNC(SleepConfig*, sleep_config_free);
+
+int parse_sleep_config(SleepConfig **sleep_config);
+
+typedef enum SleepSupport {
+ SLEEP_SUPPORTED,
+ SLEEP_DISABLED, /* Disabled in SleepConfig.allow */
+ SLEEP_NOT_CONFIGURED, /* SleepConfig.states is not configured */
+ SLEEP_STATE_OR_MODE_NOT_SUPPORTED, /* SleepConfig.states/modes are not supported by kernel */
+ SLEEP_RESUME_NOT_SUPPORTED,
+ SLEEP_NOT_ENOUGH_SWAP_SPACE,
+ SLEEP_ALARM_NOT_SUPPORTED, /* CLOCK_BOOTTIME_ALARM is unsupported by kernel (only used by s2h) */
+} SleepSupport;
+
+int sleep_supported_full(SleepOperation operation, SleepSupport *ret_support);
+static inline int sleep_supported(SleepOperation operation) {
+ return sleep_supported_full(operation, NULL);
+}
+
+/* Only for test-sleep-config */
+int sleep_state_supported(char **states);
+int sleep_mode_supported(char **modes);