Merge tag 'mm-hotfixes-stable-2025-07-11-16-16' of git://git.kernel.org/pub/scm/linux...
[linux-2.6-block.git] / include / linux / alarmtimer.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
ff3ead96
JS
2#ifndef _LINUX_ALARMTIMER_H
3#define _LINUX_ALARMTIMER_H
4
5#include <linux/time.h>
6#include <linux/hrtimer.h>
7#include <linux/timerqueue.h>
3758b0f8
TG
8
9struct rtc_device;
ff3ead96
JS
10
11enum alarmtimer_type {
12 ALARM_REALTIME,
13 ALARM_BOOTTIME,
14
4a057549 15 /* Supported types end here */
ff3ead96 16 ALARM_NUMTYPE,
4a057549
BW
17
18 /* Used for tracing information. No usable types. */
19 ALARM_REALTIME_FREEZER,
20 ALARM_BOOTTIME_FREEZER,
ff3ead96
JS
21};
22
a28cde81
JS
23#define ALARMTIMER_STATE_INACTIVE 0x00
24#define ALARMTIMER_STATE_ENQUEUED 0x01
a28cde81 25
180bf812
JS
26/**
27 * struct alarm - Alarm timer structure
28 * @node: timerqueue node for adding to the event list this value
29 * also includes the expiration time.
af4afb40 30 * @timer: hrtimer used to schedule events while running
180bf812 31 * @function: Function pointer to be executed when the timer fires.
af4afb40
PP
32 * @type: Alarm type (BOOTTIME/REALTIME).
33 * @state: Flag that represents if the alarm is set to fire or not.
180bf812
JS
34 * @data: Internal data value.
35 */
ff3ead96
JS
36struct alarm {
37 struct timerqueue_node node;
dae373be 38 struct hrtimer timer;
2634303f 39 void (*function)(struct alarm *, ktime_t now);
ff3ead96 40 enum alarmtimer_type type;
a28cde81 41 int state;
ff3ead96
JS
42 void *data;
43};
44
45void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
2634303f 46 void (*function)(struct alarm *, ktime_t));
b193217e
TG
47void alarm_start(struct alarm *alarm, ktime_t start);
48void alarm_start_relative(struct alarm *alarm, ktime_t start);
6cffe00f 49void alarm_restart(struct alarm *alarm);
9082c465
JS
50int alarm_try_to_cancel(struct alarm *alarm);
51int alarm_cancel(struct alarm *alarm);
ff3ead96 52
dce75a8c 53u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
6cffe00f
TP
54u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
55ktime_t alarm_expires_remaining(const struct alarm *alarm);
dce75a8c 56
fd928f3e 57#ifdef CONFIG_RTC_CLASS
57c498fa
JS
58/* Provide way to access the rtc device being used by alarmtimers */
59struct rtc_device *alarmtimer_get_rtcdev(void);
fd928f3e
SB
60#else
61static inline struct rtc_device *alarmtimer_get_rtcdev(void) { return NULL; }
62#endif
57c498fa 63
ff3ead96 64#endif