xref: /dflybsd-src/sys/dev/drm/include/linux/hrtimer.h (revision e7ab7444656f42b58710bab5c1a1a9eeb91d9def)
15915b712SFrançois Tigeot /*
2eaf74c33SFrançois Tigeot  * Copyright (c) 2017-2019 François Tigeot <ftigeot@wolfpond.org>
35915b712SFrançois Tigeot  * All rights reserved.
45915b712SFrançois Tigeot  *
55915b712SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
65915b712SFrançois Tigeot  * modification, are permitted provided that the following conditions
75915b712SFrançois Tigeot  * are met:
85915b712SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
95915b712SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
105915b712SFrançois Tigeot  *    disclaimer.
115915b712SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
125915b712SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
135915b712SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
145915b712SFrançois Tigeot  *
155915b712SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
165915b712SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
175915b712SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
185915b712SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
195915b712SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
205915b712SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
215915b712SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
225915b712SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
235915b712SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
245915b712SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
255915b712SFrançois Tigeot  */
265915b712SFrançois Tigeot #ifndef _LINUX_HRTIMER_H_
275915b712SFrançois Tigeot #define _LINUX_HRTIMER_H_
285915b712SFrançois Tigeot 
29eaf74c33SFrançois Tigeot #include <linux/rbtree.h>
305915b712SFrançois Tigeot #include <linux/ktime.h>
31eaf74c33SFrançois Tigeot #include <linux/init.h>
325915b712SFrançois Tigeot #include <linux/list.h>
335915b712SFrançois Tigeot #include <linux/wait.h>
345915b712SFrançois Tigeot #include <linux/timer.h>
355915b712SFrançois Tigeot 
365915b712SFrançois Tigeot enum hrtimer_mode {
375915b712SFrançois Tigeot 	HRTIMER_MODE_ABS = 0x0,
385915b712SFrançois Tigeot 	HRTIMER_MODE_REL = 0x1,
395915b712SFrançois Tigeot };
405915b712SFrançois Tigeot 
415915b712SFrançois Tigeot enum hrtimer_restart {
425915b712SFrançois Tigeot 	HRTIMER_NORESTART,	/* Timer is not restarted */
435915b712SFrançois Tigeot 	HRTIMER_RESTART,	/* Timer must be restarted */
445915b712SFrançois Tigeot };
455915b712SFrançois Tigeot 
465915b712SFrançois Tigeot struct hrtimer {
475915b712SFrançois Tigeot 	struct callout timer_callout;
485915b712SFrançois Tigeot 	clockid_t 		clock_id;
495915b712SFrançois Tigeot 	enum hrtimer_mode	ht_mode;
505915b712SFrançois Tigeot 	bool active;
515915b712SFrançois Tigeot 	enum hrtimer_restart	(*function)(struct hrtimer *);
525915b712SFrançois Tigeot 	struct lwkt_token timer_token;
535915b712SFrançois Tigeot };
545915b712SFrançois Tigeot 
555915b712SFrançois Tigeot extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
565915b712SFrançois Tigeot 			 enum hrtimer_mode mode);
575915b712SFrançois Tigeot 
585915b712SFrançois Tigeot extern void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
595915b712SFrançois Tigeot 				   u64 range_ns, const enum hrtimer_mode mode);
605915b712SFrançois Tigeot 
615915b712SFrançois Tigeot extern int hrtimer_cancel(struct hrtimer *timer);
625915b712SFrançois Tigeot 
635915b712SFrançois Tigeot extern bool hrtimer_active(const struct hrtimer *timer);
645915b712SFrançois Tigeot 
65*e7ab7444SFrançois Tigeot static inline void
hrtimer_start(struct hrtimer * timer,ktime_t tim,const enum hrtimer_mode mode)66*e7ab7444SFrançois Tigeot hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
67*e7ab7444SFrançois Tigeot {
68*e7ab7444SFrançois Tigeot 	hrtimer_start_range_ns(timer, tim, 0, mode);
69*e7ab7444SFrançois Tigeot }
70*e7ab7444SFrançois Tigeot 
71*e7ab7444SFrançois Tigeot static inline void
hrtimer_set_expires(struct hrtimer * timer,ktime_t time)72*e7ab7444SFrançois Tigeot hrtimer_set_expires(struct hrtimer *timer, ktime_t time)
73*e7ab7444SFrançois Tigeot {
74*e7ab7444SFrançois Tigeot 	/* XXX: hrtimer_set_expires() not implemented */
75*e7ab7444SFrançois Tigeot }
76*e7ab7444SFrançois Tigeot 
775915b712SFrançois Tigeot #endif /* _LINUX_HRTIMER_H_ */
78