]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/sleep-config.h
battery-util: move battery_is_discharging_and_low() to battery-util.[ch]
[thirdparty/systemd.git] / src / shared / sleep-config.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
0ef6f454
LP
2#pragma once
3
17c40b3a 4#include <linux/fiemap.h>
746cf898
SS
5
6#include "hashmap.h"
c58493c0
ML
7#include "time-util.h"
8
4f58b656
YW
9#define DEFAULT_SUSPEND_ESTIMATION_USEC (1 * USEC_PER_HOUR)
10
be2a4b0d
LP
11typedef enum SleepOperation {
12 SLEEP_SUSPEND,
13 SLEEP_HIBERNATE,
14 SLEEP_HYBRID_SLEEP,
15 SLEEP_SUSPEND_THEN_HIBERNATE,
16 _SLEEP_OPERATION_MAX,
17 _SLEEP_OPERATION_INVALID = -EINVAL,
18} SleepOperation;
19
28ca9c24 20typedef struct SleepConfig {
c8cd8ca3
LP
21 bool allow[_SLEEP_OPERATION_MAX];
22 char **modes[_SLEEP_OPERATION_MAX];
23 char **states[_SLEEP_OPERATION_MAX];
3d23df00 24 usec_t hibernate_delay_usec;
4f58b656 25 usec_t suspend_estimation_usec;
28ca9c24
ZS
26} SleepConfig;
27
1326de01 28SleepConfig* free_sleep_config(SleepConfig *sc);
28ca9c24
ZS
29DEFINE_TRIVIAL_CLEANUP_FUNC(SleepConfig*, free_sleep_config);
30
7bdf56a2
ZS
31/* entry in /proc/swaps */
32typedef struct SwapEntry {
33 char *device;
34 char *type;
35 uint64_t size;
36 uint64_t used;
37 int priority;
38} SwapEntry;
39
40SwapEntry* swap_entry_free(SwapEntry *se);
41DEFINE_TRIVIAL_CLEANUP_FUNC(SwapEntry*, swap_entry_free);
42
43/*
44 * represents values for /sys/power/resume & /sys/power/resume_offset
45 * and the matching /proc/swap entry.
46 */
47typedef struct HibernateLocation {
52133271
ZS
48 dev_t devno;
49 uint64_t offset;
7bdf56a2
ZS
50 SwapEntry *swap;
51} HibernateLocation;
52
53HibernateLocation* hibernate_location_free(HibernateLocation *hl);
54DEFINE_TRIVIAL_CLEANUP_FUNC(HibernateLocation*, hibernate_location_free);
55
17c40b3a 56int read_fiemap(int fd, struct fiemap **ret);
28ca9c24 57int parse_sleep_config(SleepConfig **sleep_config);
7bdf56a2 58int find_hibernate_location(HibernateLocation **ret_hibernate_location);
19adb8a3 59
c8cd8ca3 60int can_sleep(SleepOperation operation);
19adb8a3
ZJS
61int can_sleep_disk(char **types);
62int can_sleep_state(char **types);
746cf898
SS
63int get_total_suspend_interval(Hashmap *last_capacity, usec_t *ret);
64int fetch_batteries_capacity_by_name(Hashmap **ret_current_capacity);
31f62bdd 65int get_capacity_by_name(Hashmap *capacities_by_name, const char *name);
746cf898
SS
66int estimate_battery_discharge_rate_per_hour(
67 Hashmap *last_capacity,
68 Hashmap *current_capacity,
69 usec_t before_timestamp,
70 usec_t after_timestamp);
1afe3d71
SS
71int check_wakeup_type(void);
72int battery_trip_point_alarm_exists(void);
be2a4b0d
LP
73
74const char* sleep_operation_to_string(SleepOperation s) _const_;
75SleepOperation sleep_operation_from_string(const char *s) _pure_;