alarmtimer.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_ALARMTIMER_H
  3. #define _LINUX_ALARMTIMER_H
  4. #include <linux/time.h>
  5. #include <linux/hrtimer.h>
  6. #include <linux/timerqueue.h>
  7. struct rtc_device;
  8. enum alarmtimer_type {
  9. ALARM_REALTIME,
  10. ALARM_BOOTTIME,
  11. /* Supported types end here */
  12. ALARM_NUMTYPE,
  13. /* Used for tracing information. No usable types. */
  14. ALARM_REALTIME_FREEZER,
  15. ALARM_BOOTTIME_FREEZER,
  16. };
  17. enum alarmtimer_restart {
  18. ALARMTIMER_NORESTART,
  19. ALARMTIMER_RESTART,
  20. };
  21. #define ALARMTIMER_STATE_INACTIVE 0x00
  22. #define ALARMTIMER_STATE_ENQUEUED 0x01
  23. /**
  24. * struct alarm - Alarm timer structure
  25. * @node: timerqueue node for adding to the event list this value
  26. * also includes the expiration time.
  27. * @timer: hrtimer used to schedule events while running
  28. * @function: Function pointer to be executed when the timer fires.
  29. * @type: Alarm type (BOOTTIME/REALTIME).
  30. * @state: Flag that represents if the alarm is set to fire or not.
  31. * @data: Internal data value.
  32. */
  33. struct alarm {
  34. struct timerqueue_node node;
  35. struct hrtimer timer;
  36. enum alarmtimer_restart (*function)(struct alarm *, ktime_t now);
  37. enum alarmtimer_type type;
  38. int state;
  39. void *data;
  40. };
  41. void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
  42. enum alarmtimer_restart (*function)(struct alarm *, ktime_t));
  43. void alarm_start(struct alarm *alarm, ktime_t start);
  44. void alarm_start_relative(struct alarm *alarm, ktime_t start);
  45. void alarm_restart(struct alarm *alarm);
  46. int alarm_try_to_cancel(struct alarm *alarm);
  47. int alarm_cancel(struct alarm *alarm);
  48. u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval);
  49. u64 alarm_forward_now(struct alarm *alarm, ktime_t interval);
  50. ktime_t alarm_expires_remaining(const struct alarm *alarm);
  51. #ifdef CONFIG_RTC_CLASS
  52. /* Provide way to access the rtc device being used by alarmtimers */
  53. struct rtc_device *alarmtimer_get_rtcdev(void);
  54. #else
  55. static inline struct rtc_device *alarmtimer_get_rtcdev(void) { return NULL; }
  56. #endif
  57. #endif